Numbering Systems and Computer Codes
Prepared by The Computer Information Systems Department


Decimal Numbering Systems:
The decimal numbering system is a base 10 numbering system (this means there are 10 digits we can use - these digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9). When we talk about a number, we understand what the number is because of its face value and its positional value. Thus, the digit 5 has a different meaning when it is in the tens position than when it is in the ones position (i.e. when it is in the tens position, we express it as 50 and when it is in the ones position, we express it as 5). In this case, the face value of the digit is 5 and the positional value of a number is based on the position it occupies. In decimal, the positional value of a number is based on the powers of 10 (remember, we are in base 10):
5 7 2 4 Face value
103 102 101 100 Positional Value (powers of 10)
1000 100 10 1 Resolved positional value

To figure out the value of 5724, we do the following:

5 x 103 = 5 x 1000 =
5000
7 x 102 = 7 x 100 =
700
2 x 101 = 2 x 10 =
20
4 x 100 = 4 x 1 =
4
 
5724

Binary Numbering systems:
The binary numbering system works much the same way as the decimal numbering system except that now we are in base 2 so we only have 2 digits (0, 1). The value of the number is still determined by the face value times the positional value, but since we are in base 2, the positional values are the powers of 2. Since the face values can only be 0 or 1, this means that the 0 or 1 is multiplied by the positional place in which it is found.
Example: binary number 1011011

1 0 1 1 0 1 1 Face value
26 25 24 23 22 21 20 Positional value
64 32 16 8 4 2 1 Resolved positional value

The positional values are first shown in the powers of 2 and then as the resolved number - in other words, 2 to the 6th is equal to 64.

Converting binary to decimal:
In the previous example to find the decimal equivalent for the number 1011011, we do the following:

1 x 26 = 1 x 64 =
64
0 x 25 = 0 x 32 =
0
1 x 24 = 1 x 16 =
16
1 x 23 = 1 x 8 =
8
0 x 22 = 0 x 4 =
0
1 x 21 = 1 x 2 =
2
1 x 20 = 1 x 1 =
1
 
91

Converting decimal to binary:
Before doing this it is important that we review the decimal equivalent for the frequently used powers of 2:

20 = 1 21 = 2 22 = 4 23 = 8 24 = 16 25 = 32
26 = 64 27 = 128 28 = 256 29 = 512 210 = 1024 etc.

To convert 91 from decimal to binary, you can follow the following steps:
  1. Look at 91 and see what power of 2 can be taken from it. The highest power that can be subtracted is 2 to the 6th which is 64. Therefore we put a 1 in the 2 to the 6th position. Then we subtract: 91 - 64 = 27
    1
    _____
    _____
    _____
    _____
    _____
    _____
    26
    25
    24
    23
    22
    21
    20
    64
    32
    16
    8
    4
    2
    1

  2. Now we look at what is left, 27 and see if the next power of 2 (moving to the right) which is 2 to the 5th or 32 can be subtracted from 27. It can't, therefore we didn't use the 2 to the 5th position so we put a 0 in the 2 to the 5th position. Since we didn't use the 32, there is no subtraction.
    1
    0
    _____
    _____
    _____
    _____
    _____
    26
    25
    24
    23
    22
    21
    20
    64
    32
    16
    8
    4
    2
    1

  3. Now we check to see if the next power of 2 (moving to the right) which is 2 to the 4th with the value of 16 can be subtracted from 27. It can, therefore we put a 1 in the 2 to the 4th position. Then we subtract: 27 - 16 = 11.
    1
    0
    1
    _____
    _____
    _____
    _____
    26
    25
    24
    23
    22
    21
    20
    64
    32
    16
    8
    4
    2
    1

  4. Now, we look at the next power of 2 which is 2 to the 3rd which resolves to 8 and check to see if 8 can be subtracted from 11. It can, therefore we put a 1 in the 2 to the 3rd position. Then we subtract 11 - 8 = 3
    1
    0
    1
    1
    _____
    _____
    _____
    26
    25
    24
    23
    22
    21
    20
    64
    32
    16
    8
    4
    2
    1

  5. Next, we look at the next power or 2 which is 2 to the 2nd which resolves to 4 and check to see if 4 can be subtracted from 3. It can't therefore we didn't use the 2 to the 2nd so we put a 0 in the 2 to the 2nd position. Since we didn't use the 4, there is no subtraction.
    1
    0
    1
    1
    0
    _____
    _____
    26
    25
    24
    23
    22
    21
    20
    64
    32
    16
    8
    4
    2
    1

  6. In the next step, we look at 2 to the 1st power which resolves to 2 and check to see if 2 can be subtracted from 3. It can therefore we put a 1 in the 2 to the 1st position. Then we subtract: 3 - 2 = 1
    1
    0
    1
    1
    0
    1
    _____
    26
    25
    24
    23
    22
    21
    20
    64
    32
    16
    8
    4
    2
    1

  7. Finally, we have 1 left and we look at the resolution of the 2 to the 0th position which is 1 and see that this subtraction will reduce us to 0, indicating that we have handled the conversion correctly. We put a 1 in the 2 to the 0th position. Then we subtract: 1 - 1 = 0
    1
    0
    1
    1
    0
    1
    1
    26
    25
    24
    23
    22
    21
    20
    64
    32
    16
    8
    4
    2
    1
    We now see that the decimal number 91 is equivalent to 1011011 in binary.

Binary counting:
Now, we are going to learn to count in binary and relate counting in binary to counting in decimal. 0 and 1 are the same values in binary and decimal but then we come to add 1 to 1 and we discover that there is no 2 in binary. Essentially we have run out of digits. We stop and think what we do in decimal when we run out of digits and we get the pattern to use in binary. For example, in decimal when we try to add 1 to 9, we run out of digits.

In decimal:
9
  In binary:
1
 
+1
   
+1
 
10
   
10
What we find is that when we run out of digits, we simply go to the next position - we call this putting down the 0 and carrying the 1.

Continuing along:
10
11
100
101
110
111
1000
+ 1
+ 1
+  1
+  1
+  1
+   1
+   1
11
100
101
110
111
1000
1001

This means that when we count, we get the following:
Decimal
Binary
0
0
1
1
2
10
3
11
4
100
5
101
6
110
7
111
8
1000
9
1001
10
1010
11
1011
12
1100
13
1101
14
1110
15
1111
16
10000

Hexadecimal Numbering System:

The next numbering system is the hexadecimal numbering system. This is the base 16 numbering system, therefore there are 16 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F). The letter A carries the same value as decimal 10, the letter B carries the same value as decimal 11, the letter C carries the same value as decimal 12, the letter D carries the same value as decimal 13, the letter E carries the same value as decimal 14, and the letter F carries the same value as decimal 15. Hexadecimal, like any other numbering system has the face value of digits and the positional value. The positional value is based on the powers of 16 since hexadecimal is the base 16 numbering system.

Example: Hexadecimal number A359
A 3 5 9 face value
163 162 161 160 positional value (powers of 16)
4096 256 16 1 resolved positional value

Converting hexadecimal to decimal:
To convert hexadecimal to its decimal equivalent, we multiply the face value times the positional value:
A x 163 = 10 x 4096 =
40960
(note A is equivalent to decimal 10)
3 x 162 =  3 x   256 =
768
 
5 x 161 =  5 x    16 =
80
 
9 x 160 =  9 x     1 =
9
 
 
         
   
41817
 

The equivalent of hexadecimal A359 in decimal is 41817.

Converting decimal to hexadecimal:

Now we will take the decimal number 41817 and convert it back to hexadecimal. To do this, we will follow the same steps we used in converting decimal to binary with one change – this time we are concerned with multiplying by the face value (in binary this was not a concern because multiplying by 1 doesn’t change anything).

The following are the decimal equivalents for some of the commonly used powers of 16:
160 = 1 161 = 16 162 = 256 163 = 4096 164 = 65536

The following steps convert decimal 41817 to hexadecimal:
  1. First we need to find out the highest base of 16 that can be subtracted from our number, 41817. Clearly 16 to the 4th which is equivalent to 65536 is too big. However, 16 to the 3rd which is equivalent to 4096 will work. Our next question is how many 16 to the 3rd s can be subtracted from 41817. Through trying different calculations, we discover that 10 x 4096 or 40960 is the most powers of 16 to the 3rd that we can subtract so we place A (the equivalent of 10) in the 16 to the 3rd position.
    We subtract: 41817 – 40960 = 857
    A _____ _____ _____
    163 162 161 160
    4096 256 16 1
  2. Now, we have established the first power of 16 that we can use. We now move over to 16 to the 2nd power which has the equivalent of 256 and ask how many times can 256 be subtracted from 857. Again, we try the calculations and discover 3 256s (768) can be subtracted from 857 which means we enter a 3 in the 16 to the 2nd position.
    We subtract: 857-768 = 89
    A 3 _____ _____
    163 162 161 160
    4096 256 16 1
  3. Now we have 89 left. Looking at 16 to the 1st with the equivalent of 16, we ask how many 16s can be subtracted from 89. The answer is 5 (16 x 5 = 80), so we place a 5 in the 16 to the 1st position.
    We subtract: 89 – 80 = 9
    A 3 5 _____
    163 162 161 160
    4096 256 16 1
  4. Now we have 9 left. There is only the 16 to the 0th position with the equivalent value of 1 left. Clearly if we subtract 9 x 1 from 9 we will have 0 left and that is our goal, so we place a 9 in the 16 to the 0th position.
    We subtract: 9-9=0
    A 3 5 9
    163 162 161 160
    4096 256 16 1
We now see that the decimal number 41817 is equivalent to A359 in hexadecimal.

Counting in hexadecimal:
Counting in hexadecimal is the same as in decimal through decimal 9. But once we reach 9, we have run out of digits in decimal but we have 6 digits (A, B, C, D, E, F) left in hexadecimal. Therefore when we reach 9 in hexadecimal we can keep counting through A, B, C, D, E and F. Note that 9 + 1 = A in hexadecimal and A + 1 = B, etc. When we add 1 to F, we see that there are no more digits so we have to put down the 0 and carry the one over to the next position – therefore, 1 + F = 10.
Binary
Decimal
Hexadecimal
0
0
0
1
1
1
10
2
2
11
3
3
100
4
4
101
5
5
110
6
6
111
7
7
1000
8
8
1001
9
9
1010
10
A
1011
11
B
1100
12
C
1101
13
D
1110
14
E
1111
15
F
10000
16
10
10001
17
11
10010
18
12

Conversion from binary to hexadecimal:
Binary
Hexadecimal
0000
0
0001
1
0010
2
0011
3
0100
4
0101
5
0110
6
0111
7
1000
8
1001
9
1010
A
1011
B
1100
C
1101
D
1110
E
1111
F

As you can see from the chart above, every hexadecimal digit can be represented by 4 binary digits (bits) and every combination of 4 binary digits can be represented by a single hexadecimal digit. Because of this, any string of 4 binary digits can be converted to its hexadecimal equivalent by either checking the chart above or doing the conversion. If I have a string of binary digits, it can be divided into groups of four starting at the far right and each group can be converted to its hexadecimal equivalent.

Examples:
  1. 11001111 can be divided into groups of 4
    1100/ 1111    1100 is C and 1111 is F
    C
    F
     
    therefore the hexadecimal equivalent of 11001111 is CF

  2. the hexadecimal equivalent of 11010101110101 is 3575
    11010101110101 = 11/ 0101/ 0111/ 0101
     
    3
    5
    7
    5
Note that if there are not enough digits to make groups of 4, then you start at the right and the group with less than 4 digits is the leftmost group – in translating that group, assume leading 0s.

Conversion from hexadecimal to binary:
To convert from hexadecimal to binary, you express each hexadecimal character as 4 binary digits – either use the chart above or figure out the equivalent.

Example:
Convert the hexadecimal number 5E49 to binary:
5
E
4
9
0101
1110
0100
1001

Hexadecimal 5E49 is equal to binary 0101111001001001 (note, the leading 0 could be omitted without hurting the validity of the number).

Comptuer Codes:
The letters, numbers and special characters that we input into the computer are stored using a computer code. The computer code is a way of representing each character using only the 0 and 1 binary bits that the computer understands. Two computer codes that are used today are EBCDIC and ASCII. ASCII is the code that is used on your microcomputer.

EBCDIC (Extended Binary Coded Decimal Interchange Code):
EBCDIC is a 8 bit code where the left four bits are called the zone and the right four bits are called the digit portion. The zone part of the code tells what “group” the character is part of, while the digit part of the code identifies the specific character within the group. EBCDIC has codes for upper case and lower case letters, numbers and special characters. This handout will deal only with upper case letters and numbers.
The structure of the EBCDIC code is:
_ _ _ _ _ _ _ _
z o n e/ d i g it

Zone:   1 1       The 11 in the first two digits of the zone indicates an upper case letter or a number.
The last two digits of the zone represent the group or range:
code range
00 A - I
01 J - R
10 S - Z
11 numbers

digit: __ __ __ __
  23 22 21 20
  8 4 2 1

Using the binary powers of 2, we can determine a value for each bit within the digit portion of the code. For example, since A is the first character in its group (A – I), we would use the digit portion of the code to indicate a 1. Since B is the second character in the group A – I, we would use the digit portion of the code to indicate a binary equivalent of a 2. Since C is the third character in the group A – I, we would use the digit portion of the code to indicate the binary equivalent of a 3.

Examples:
  1. If we want to represent the letter F, we will first determine the digit portion of the code. We first determine that it is the 6th letter within the range (range A – I). Now we have to figure out how to express 6 in binary. We find that by turning on (putting a 1) over the positional value of 4 (22) and turning on (putting a 1) over the positional value of 2 (21) we have the equivalent of 6 (4 + 2 = 6). We do not need the 8 (23) or the 1 (20) so we put a 0 in these positions.
    0 1 1 0
    23 22 21 20
    8 4 2 1
    Note: 4 and 2 turned on and 4 + 2 = 6

    Looking at the zone portion, we know that F is upper case so we put a 11 in the first two characters of the zone. We also know that it is in the range A – I and we know that the range A – I calls for entering 00 in the last two characters of the zone. This gives us a zone of: 1 1 0 0
    Combining the zone portion of 1 1 0 0 and the digit portion of 0 1 1 0 we find that the EBCDIC code for the letter F is 1 1 0 0 0 1 1 0.

  2. The character M: M is the 4th letter in the range J – P

    The zone is: 1 1 for upper case followed by 0 1 for the range J – P.

    The digit is: since M is the 4th letter in the range, the position with the value of 4 is turned on by placing a 1 there and the other positions are turned off by using 0.
    0 1 0 0
    23 22 21 20
    8 4 2 1
    The EBCDIC code for the character M is: 1 1 0 1 0 1 0 0

  3. The number 9: 9 is the 9th number in the number group

    The zone is: 1 1 for upper case letter or number followed by 1 1 for the numbers range.

    The digit is: since 9 is the 9th number in the range, we need to find a way to represent a 9. Turning on the 8 and the 1 will accomplish this, so a 1 is placed in these two positions. This means the positions with a value of 4 and 2 are not used, so a 0 is placed in these positions.
    1 0 0 1
    23 22 21 20
    8 4 2 1
    The EBCDIC code for the number 9 is: 1 1 1 1 1 0 0 1

  4. The letter S: There are only 8 characters in the range S – Z, so S is considered the second character in the range while Z is the 9th (in other words, there is no first character in the range S – Z).

    The zone is: 1 1 for upper case followed by 1 0 for the range S – Z.

    The digit is: Since S is considered the second letter in the range, we need to represent the number 2 by turning on (putting a 1) in the position with a value of 2 and 0 in all other positions.
    0 0 1 0
    23 22 21 20
    8 4 2 1
    The EBCDIC code for the letter S is: 1 1 1 0 0 0 1 0
Hexadecimal translation of EBCDIC:
Instead of dealing with the 8-bit binary code when looking at memory dumps etc., the programmer usually deals with the hexadecimal translation of EBCDIC. One hexadecimal character is used to translate the 4-bit digit portion of the EBCDIC. Hexadecimal is used to represent EBCDIC because of their unique relationship: any 4-bit binary number can be represented by a single hexadecimal character and any hexadecimal character can be represented by 4 binary bits.

Binary
Hexadecimal
0000
0
0001
1
0010
2
0011
3
0100
4
0101
5
0110
6
0111
7
1000
8
1001
9
1010
A
1011
B
1100
C
1101
D
1110
E
1111
F


Examples:
1.
F = 11000110
1100
0110
in EBCDIC
 
C
6
hexadecimal translation of EBCDIC
2.
M = 11010100
1101
0100
in EBCDIC
 
4
hexadecimal translation of EBCDIC
3.
9 = 11111001
1111 
1001 
in EBCDIC
 
F
9
hexadecimal translation of EBCDIC
4.
S = 11100010
1110
0010
in EBCDIC
 
E
2
hexadecimal translation of EBCDIC


Looking at all of the upper case letters and the numbers or digits from 0 to 9, it can be seen that there is a pattern. For example, any character in the range A - I has a zone of 1100 which can be represented by hexadecimal C. This means that if we are looking gat a dump, etc., we know that any hexadecimal translation of EBCDIC that has a C is in the range A - I.

Characters
EBCDIC Zone
Hexadecimal representation
A -I
1100
C
J - R
1101
D
S - Z
1110
E
numbers
1111
F


Decimal Equivalents of EBCDIC:
Another way of representing EBCDIC is using the decimal equivalent of the entire 8 bit code binary code:
A = 1 1 0 0 0 0 0 1 Face value
27 26 25 24 23 22 21 20 Powers of 2
128 64 32 16 8 4 2 1 Positional value from appropriate power of 2

Therefore, A = 128 + 64 + 1 = 193.

EBCDIC equivalents:
Character EBCDIC Equivalent Character EBCDIC Equivalent
A 193 N 213
B 194 O 214
C 195 P 215
D 196 Q 216
E 197 R 217
F 198 S 226
G 199 T 227
H 200 U 228
I 201 V 229
J 209 W 230
K 210 X 231
L 211 Y 232
M 212 Z 233


ASCII (American Standard Code for Information Interchange):
Most PCs can handle ASCII files and so if you store a file in ASCII it is usually transportable from system to system. There is a standard 7 bit ASCII code that has characters whose binary code translates into the decimal numbers from 0 to 127. In this set, codes 0 through 32 are control codes that handle things like form feed and carriage control while codes 33 through 127 are a set of printable characters. For example, codes 65 through 90 represent uppercase letters and codes 48 through 57 represent the digits 0 through 9. However, most computers handle 8 bit codes so it is possible to generate 128 additional ASCII codes, which are called the extended ASCII character set. These codes are not standardized and are sued differently by different computer manufacturers. When representing the standard 7 bit ASCII codes as 8 bit codes, a leading 0 is added as the left-most character. When dealing with ASCII code, the left most bits will tell us the type of character being represented and the right bits will indicate which one in the range. For example, 011 in the left most three bits of the standard 7 bit code indicates a number with 0 having 0000 standing for 1 and 1001 standing for 9. Notice the use of the positional value of the bits to indicate which number is being represented.
__ __ __ __
23 22 21 20
8 4 2 1

The number 0 uses 4 0s in this configuration to represent a decimal value of 0.
0 0 0 0
23 22 21 20
8 4 2 1

The number 0 in 7 bit ASCII is 0110000.
The number 9 uses a 1 in the bit with a positional value of 8 and a 1 in the bit with a positional value of 1 with a 0 in the bits with positional values of 4 and 2. Therefore you have 8 + 1 turned on for a value of 9.
1 0 0 1
23 22 21 20
8 4 2 1

The number 9 in 7 bit ASCII is 0111001.

The bits 1 0 in the left most bits of the standard 7 bit code indicate an upper case letter with the last 5 bits specifying the exact letter. Since there are 26 upper case letters in the alphabet, 5 bits are needed to tell which one is being represented.
__ __ __ __ __ face value
24 23 22 21 20 positional value in powers of 2
16 8 4 2 1 positional value in decimal

Using these five positions, numbers from 1 to 26 can be represented standing for the letters A – Z.

The letter A only turns on the positional value of 1 since it is the first letter in the alphabet.
__ __ __ __ 1 face value
24 23 22 21 20 positional value in powers of 2
16 8 4 2 1 positional value in decimal

Combining the 10 indicating an upper case letter and the 00001 indicating the first letter, the letter A in 7 bit ASCII is 1000001.

The letter L turns on the positional value of 8 and the positional value of 4 to add up to 12 since it is the 12th letter in the alphabet.
0 1 1 0 0 face value
24 23 22 21 20 positional value in powers of 2
16 8 4 2 1 positional value in decimal

Combining the 10 indicating an upper case letter and the 01100 indicating the 12th letter, the letter L in 7 bit ASCII is 1001100.

The letter Z turns on the positional value of 16 and the positional value of 8 and the positional value of 2 to add up to 26 since it is the 26th letter of the alphabet.
1 1 0 1 0 face value
24 23 22 21 20 positional value in powers of 2
16 8 4 2 1 positional value in decimal

Combining the 10 indicating an upper case letter and the 11010 indicating the 26th letter, the letter Z in 7 bit ASCII is 1011010.

ASCII Equivalent represented in decimal translation of binary code:
When working with ASCII, again it is difficult to deal with the 7 or 8 bit string of binary digits. Therefore, frequently the code is represented by the decimal equivalent of the binary code for ease of use.
__ __ __ __ __ __ __ face value
26 25 24 23 22 21 20 positional value in powers of 2
64 32 16 8 4 2 1 positional value in decimal

To do this the binary code is represented as shown above. If the position is turned on with a 1, the decimal equivalent is added to the total.

Examples:
The letter L has an equivalent value of 76 as shown:
1 0 0 1 1 0 0 face value
26 25 24 23 22 21 20 positional value in powers of 2
64 32 16 8 4 2 1 positional value in decimal

The equivalent value is therefore 64 + 8 + 4 for a total of 76.

The letter Z has an equivalent value of 90 as shown:
1 0 1 1 0 1 0 face value
26 25 24 23 22 21 20 positional value in powers of 2
64 32 16 8 4 2 1 positional value in decimal

The equivalent value is therefore 64 + 16 + 8 + 2 for a total of 90.

The chart of ASCII equivalents for the upper case letters is shown below:
Character ASCII Equivalent Character ASCII Equivalent
A 65 N 78
B 66 O 79
C 67 P 80
D 68 Q 81
E 69 R 82
F 70 S 83
G 71 T 84
H 72 U 85
I 73 V 86
J 74 W 87
K 75 X 88
L 76 Y 89
M 77 Z 90