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 if 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

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
+0123456789
00123456789
112345678910
2234567891011
33456789101112
445678910111213
5567891011121314
66789101112131415
778910111213141516
8891011121314151617
99101112131415161718

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
+01234567
001234567
1123456710
22345671011
334567101112
4456710111213
55671011121314
667101112131415
7710111213141516

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 how 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
+0123456789ABCDEF
00123456789ABCDEF
1123456789ABCDEF10
223456789ABCDEF1011
33456789ABCDEF101112
4456789ABCDEF10111213
556789ABCDEF1011121314
66789ABCDEF101112131415
7789ABCDEF10111213141516
889ABCDEF1011121314151617
99ABCDEF101112131415161718
AABCDEF10111213141516171819
BBCDEF101112131415161718191A
CCDEF101112131415161718191A1B
DDEF101112131415161718191A1B1C
EEF101112131415161718191A1B1C1D
FF101112131415161718191A1B1C1D1E

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 DFStermole
Created 9 Jan 2000
Modified 12 Jan 2000