Back to DFS's Pascal Page


Numeration Systems

(Preliminary)

Follow these fast links:

Three numeration systems, binary, octal and hexadecimal, are used when dealing with the internal workings of computers. To be a knowledgeable, efficient programmer requires at least a rudimentary understanding of how they work and how they are interrelated.

Back to Top

Binary

The most basic computer unit of data that has an address assigned to it is the byte. It consists of eight (8) bits, each of which represents a binary digit. The numeration system used in the computer is known as Binary, or Base 2.

Our usual numeration system is known as decimal or Base 10.

It would seem natural that humans would want to use the numeration system with which they are familiar. However, the computer designers realized that computers and binary were made for each other. Electricity has two states: on and off. A binary digit has two possible values: 1 and 0.

It was obvious that 1 could represent on and 0 could be off. Consider the following four basic binary addition facts,

  0   0   1    1
 +0  +1  +0   +1
 --  --  --   --
  0   1   1   10

which could be arranged in the following table.

Back to Top

Binary Addition
+01
001
1110
Binary Multiplication
x0110
0000
10110
10010100

Back to Top

Using these addition facts, we can easily count in binary up to 10002, the equivalent of 810. The red digits indicate carrying. You will note that carrying already takes place for the addition 1 + 1, when we get the first group of 2.

     1       11         1        111
  0   1  10   11  100  101  110   111
 +1  +1  +1   +1   +1   +1   +1    +1
 --  --  --  ---  ---  ---  ---   ---
  1  10  11  100  101  110  111  1000

Compare the above chart with the one for decimal below.

Back to Top

Decimal Addition
+012345678910
0012345678910
11234567891011
223456789101112
3345678910111213
44567891011121314
556789101112131415
6678910111213141516
77891011121314151617
889101112131415161718
9910111213141516171819
101011121314151617181920

Almost all would think that this table for decimal is extremely simplistic, because they already know it by heart. However, it has twenty-five times as many facts as the one for binary. Since any numerical value which can be expressed in one system can be expressed in the other, computer designers decided to use binary because they would need to make the computer handle so many fewer addition facts. This would obviously make their job as designers much simpler.

The only real problem with using binary was that the number of digits required to represent a value rose very quickly as the value increased. The table below shows the first eight place values for binary digits.

Back to Top

Decimal-Binary Conversion
DecimalBinaryPlace Value
1120
21021
410022
8100023
161000024
3210000025
64100000026
1281000000027

All values up to 25510 can be represented by combinations of 1s and 0s in binary numbers using up to a total of eight digits. For example, 1510 is equivalent to 11112 based on the sum of the place values of the 1s digits.

DecimalBinarySum of Place Values
15 =1111 =23 + 22 + 21 + 20

Back to Top

Octal

Since numbers represented in binary quickly have a great number of digits (25510 = 111111112), two other systems are used to make things easier for humans, Octal (Base 8) and Hexadecimal (Base 16). The following table illustrates counting using the whole number values from 010 to 2010 in all four bases.

Back to Top

Counting in Different Bases
Decimal (10)Binary (2)Octal (8)Hex (16)
0000
1111
21022
31133
410044
510155
611066
711177
81000108
91001119
10101012A
11101113B
12110014C
13110115D
14111016E
15111117F
16100002010
17100012111
18100102212
19100112313
20101002414

Notice that the number of the base indicates the total number of different symbols used in that system.

Octal was used originally for two reasons:

Many programmers became very proficient in their use of octal. Not only could they convert between binary and octal with ease, they could also do arithmetic in octal. A quick look at this table of octal addition facts shows that they did not have to learn much that was different from the decimal addition facts they already knew.

Back to Top

Octal Addition
+0123456710
00123456710
112345671011
2234567101112
33456710111213
445671011121314
5567101112131415
66710111213141516
771011121314151617
10101112131415161720
Octal Multiplication
x0123456710
0000000000
10123456710
202461012141620
3036111417222530
40410142024303440
50512172431364350
60614223036445260
70716253443526170
10010203040506070100

Two things conspired against the use of octal as the preferred shorthand for binary:

Back to Top

Hexadecimal

The introduction of the 8-bit byte ensured the use of hexadecimal, Base 16, in computing. Its nickname is hex. The byte could be treated as being composed of two 4-bit units, which are called nibbles -- something intermediate between a little bit and a big byte.

Life is filled with trade-offs. Making one thing easier or better often requires learning more. Consider these facts.

To directly address 128 Meg of RAM requires an address 28 bits long. This would result in an octal representation of 10 digits and in hexadecimal of 7. CPUs can now have 32 bits in a register. This would take 11 octal digits or just 8 in hexadecimal.

Binary still remains important. A single bit can serve as a boolean variable. Finding the particular bit which is being used for a boolean out of 32 bits is not easy and the programmer is prone to making mistakes. It is much easier to find the value of a specific bit by scanning the hex value for the nibble which contains it and then do the hex-digit to binary conversion using the chart below.

To convert from binary to hex, break up the binary number into groupings of four binary digits, i.e., nibbles. Then using the table below, find the corresponding hex digit for each nibble, e.g.,
1111 1101 0000 01102 = F D 0 616

Back to Top

Binary-Quartet/Hexadecimal Conversion
Binary0000000100100011010001010110011110001001101010111100110111101111
Hexadecimal0123456789ABCDEF
Decimal0123456789101112131415

There is a major downside to using hexadecimal -- there are a lot more addition facts to learn. The use of symbols with unfamiliar values (A, B, C, D, E, F) only compounds the problem. Thank goodness for hand-held calculators!

Back to Top

Hexadecimal Addition
+0123456789ABCDEF10
00123456789ABCDEF10
1123456789ABCDEF1011
223456789ABCDEF101112
33456789ABCDEF10111213
4456789ABCDEF1011121314
556789ABCDEF101112131415
66789ABCDEF10111213141516
7789ABCDEF1011121314151617
889ABCDEF101112131415161718
99ABCDEF10111213141516171819
AABCDEF101112131415161718191A
BBCDEF101112131415161718191A1B
CCDEF101112131415161718191A1B1C
DDEF101112131415161718191A1B1C1D
EEF101112131415161718191A1B1C1D1E
FF101112131415161718191A1B1C1D1E1F
10101112131415161718191A1B1C1D1E1F20

Back to Top

Hexadecimal Multiplication
x0123456789ABCDEF10
000000000000000000
10123456789ABCDEF10
202468ACE10121416181A1C1E20
30369CF1215181B1E2124272A2D30
4048C1014181C2024282C3034383C40
505AF14191E23282D32373C41464B50
606C12181E242A30363C42484E545A60
707E151C232A31383F464D545B626970
808101820283038404850586068707880
909121B242D363F48515A636C757E8790
A0A141E28323C46505A646E78828C96A0
B0B16212C37424D58636E79848F9AA5B0
C0C1824303C4854606C7884909CA8B4C0
D0D1A2734414E5B6875828F9CA9B6C3D0
E0E1C2A38465462707E8C9AA8B6C4D2E0
F0F1E2D3C4B5A69788796A5B4C3D2E1F0
100102030405060708090A0B0C0D0E0F0100

The eight bits in a byte can be used to represent 256 different values, from 010 to 25510 (in decimal) or from 016 to FF16 (in hexadecimal). Hex still has a role to play at the byte level. It is worth knowing hex and its relationships to binary and decimal.

Back to Top


© 2000-2006 DFStermole
Created 9 Jan 2000
Modified 10 Jan 2006