Understanding Number Systems in Computing
Understanding Number Systems in Computing
Number Systems
We have already seen in the previous chapter that inside a computer system, data is stored in a
format that cannot be easily read by human beings. This is the reason why input and output (I/O)
interfaces are required. Every computer stores numbers, letters, and other special characters in a
coded form. Before going into the details of these codes, it is essential to have a basic
understanding of the number system. So the goal of this chapter is to familiarize you with the basic
fundamentals of number system. It also introduces some of the commonly used number systems
by computer professionals and the relationship among them.
Number systems are basically of two types: non-positional and positional. In early days, human
beings counted on fingers. When ten fingers were not adequate, stones, pebbles, or sticks were
used to indicate values. This method of counting uses an additive approach or the non-positional
number system. In this system, we have symbols such as I for 1, II for 2, III for 3, IIII for 4, IIIII
for 5, etc. Each symbol represents the same value regardless of its position in the number and the
symbols are simply added to find out the value of a particular number. Since it is very difficult to
perform an arithmetic with such a number system, positional number systems were developed as
the centuries passed.
In a positional number system, there are only a few symbols called digits, and these symbols
represent different values depending on the position they occupy in the number. The value of each
digit in such a number is determined by three considerations:
The number system that we use in our day-to-day life is called the decimal number system. In this
system, the base is equal to 10 because there are altogether ten symbols or digits (0, 1, 2, 3, 4, 5,
6, 7, 8, 9). You know that in the decimal system, the successive positions to the left of the decimal
point represent units, tens, hundreds, thousands, etc. But you may not have given much attention
to the fact that each position represents a specific power of the base (10). For example, the decimal
number 2586 (written as 258610) consists of the digit 6 in the units position, 8 in the tens position,
5 in the hundreds position, and 2 in the thousands position, and its value can be written as:
The principles that apply to the decimal number system also apply to any other positional number
system. It is important only to keep track of the base of the number system in which we are
working.
The following two characteristics are suggested by the value of the base in all positional number
systems:
1. The value of the base determines the total number of different symbols or digits available in
the number system. The first of these choices is always zero.
2. The maximum value of a single digit is always equal to one less than the value of the base.
Some of the positional number systems commonly used in computer design and by computer
professionals are discussed below.
The binary number system is exactly like the decimal number system except that the base is 2
instead of 10. We have only two symbols or digits (0 and 1) that can be used in this number system.
Note that the largest single digit is 1 (one less than the base). Again, each position in a binary
number represents a power of the base (2). As such, in this system, the rightmost position is the
units (2°) position, the second position from the right is the 2's (21) position and proceeding in this
way we have 4's (22) position, 8's (23) position, 16's (24) position, and so on. Thus, the decimal
equivalent of the binary number 10101 (written as 101012) is:
In order to be specific about which system we are referring to, it is common practice to indicate
the base as a subscript. Thus we write:
101012 = 2110
"Binary digit" is often referred to by the common abbreviation bit. Thus, a "bit" in computer
terminology means either a 0 or a 1. A binary number consisting of 'n' bits is called an n-bit number.
Figure 3.1 lists all the 3-bit numbers along with their decimal equivalent. Remember that we have
only two digits, 0 and 1, in the binary system, and hence the binary equivalent of the decimal
number 2 has to be stated as 10 (read as one, zero).
Another important point to note is that with 3 bits (positions), only 8 (23) different patterns of 0s
and Is are possible and from Figure 3.1 it may be seen that a 3-bit number can have one of the 8
values in the range 0 to 7. In fact, it can be shown that any decimal number in the range 0 to 2""1
can be represented in the binary form as an n-bit number.
I
Biliary Decimal Equivalent
000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7
Every computer stores numbers, letters, and other special characters in binary form. There are
several occasions when computer professionals have to know the raw data contained in a
computer's memory. A common way of looking at the contents of a computer's memory is to print
out the memory contents on a line printer. This printout is called a memory dump. If memory
dumps were to be printed using binary numbers, the computer professionals would be confronted
with many pages of 0s and Is. Working with these numbers would be very difficult and error prone.
Because of the quantity of printout that would be required in a memory dump of binary digits and
the lack of digit variety (0s and Is only), two number systems, octal and hexadecimal, are used as
shortcut notations for binary. These number systems and their relationship with the binary number
system are explained below.
In the octal number system the base is 8. So in this system there are only eight symbols or digits:
0, 1,2, 3, 4, 5, 6, and 7 (8 and 9 do not exist in this system). Here also the largest single digit is 7
(one less than the base). Again, each position in an octal number represents a power of the base
(8). Thus the decimal equivalent of the octal number 2057 (written as 20578) is:
The hexadecimal number system is one with a base of 16. The base of 16 suggests choices of 16
single-character digits or symbols. The first 10 digits are the digits of the decimal number system
0, 1, 2, 3, 4, 5, 6, 7, 8, 9. The remaining six digits are denoted by the symbols A, B, C, D, E, and
F representing the decimal values 10, 11, 12, 13, 14, and 15 respectively. In the hexadecimal
number system, therefore, the letters A through F are number digits. The number A has a decimal
equivalent value of 10 and the number F has a decimal equivalent value of 15. Thus, the largest
single digit is F or 15 (one less than the base). Again, each position in the hexadecimal system
represents a power of the base (16). Thus the decimal equivalent of the hexadecimal number 1AF
(written as 1AFI6) is:
(1 x 162) + (A x 161) + (F x 16°), or
(1x256)+ (10x16) 256+160+ 15, or 431
(15xl), or
Observe that since there are only 16 digits in the hexadecimal number system, 4 bits (24 =16) are
sufficient to represent any hexadecimal number in binary.
Numbers expressed in decimal number system are much more meaningful to us than are values
expressed in any other number system. This is mainly because of the fact that we have been using
decimal numbers in our day-today life right from childhood. However, any number value in one
number system can be represented in any other number system. Because the input and the final
output values are to be in decimal, computer professionals are often required to convert numbers
in other number systems to decimal and vice-versa. There are many methods or techniques that
can be used to convert numbers from one base to another. We will see one technique used in
converting to base 10 from any other base and a second technique to be used in converting from
base 10 to any other base.
The following three steps are used to convert to a base 10 value from any other number system:
Step 1: Determine the column (positional) value of each digit (this depends on the position of the
digit and the base of the number system).
Step 2: Multiply the obtained column values (in Step 1) by the digits in the corresponding columns.
Step 3: Sum the products calculated in Step 2. The total is the equivalent value in decimal.
Example 3.1. Example 3.2.
110012 = ?10 47068 = ?,10
Solution: Solution:
Column Number (from Column Value Column Number (from right) Column Value
right)
Step 1: Positional value:
20, 21, 22, 23, …
1, 2, 4, 8, …
Solution:
1AC16 = 1 x 162 + A x 161 + C x 16°
= 1x256+10x16+12x1
= 256+ 160+ 12
= 42810
Example 3.4.
40527 = ?10
Solution:
40527 = 4x73 + 0x72 + 5x7' + 2x7°
= 4x 343+ 0x 49+ 5x7 + 2x1
= 1372 + 0 + 35+2
= 140910
Example 3.5.
40526 = ?10
Solution:
40526 = 4x63 + 0x62 + 5x61 + 2x6°
= 4x216 + 0x36 + 5x6 + 2x1
= 864 + 0 + 30 + 2
= 89610 .
Comparing this result with the result obtained in Example 3.4, we find that although the digits
(4052) are same for both the numbers, but their decimal equivalent is different.
This is because of the fact that the number in Example 3.4 is represented in base 7 number system
whereas the number in Example 3.5 is represented in base 6 number system.
Example 3.6.
110014 = ?10
Solution:
Solution:
110014 =lx44+lx43 + Ox42 + Ox41 +
1x4°
= 1 x 256 + 1 x 64 + 0x16 + 0x4 +
lxl
= 256 + 64 + 0 + 0+1
= 32110
Compare the result with Example 3.1.
Example 3.7.
IAC13 = ?10
The following four steps are used to convert a number from decimal to another base:
Step 1: Divide the decimal number to be converted by the value of the new base.
Step 2: Record the remainder from Step 1 as the rightmost digit (least significant digit) of the new
base number.
Step 3: Divide the quotient of the previous divide by the new base.
Step 4: Record the remainder from Step 3 as the next digit (to the left) of the new base number.
Repeat Steps 3 and 4, recording remainders from right to left, until the quotient becomes zero in
Step 3. Note that the last remainder thus obtained will be the most significant digit (MSD) of the
new base number.
Example 3.8.
2510 = ?2
Solution:
Steps 1 and 2: 25/2 = 12 and remainder 1
Steps 3 and 4: 12/2= 6 and remainder 0
Steps 3 and 4: 6/2 = 3 and remainder 0
Steps 3 and 4: 3/2 = 1 and remainder 1
Steps 3 and 4: 1/2= 0 and remainder 1
As mentioned in Steps 2 and 4, the remainders have to be arranged in the reverse order so that the
first remainder becomes the least significant digit (LSD) and the last remainder becomes the most
significant digit (MSD).
The following two steps are used to convert a number from a base other than 10 to a base other
than 10:
Step 1: Convert the original number to a decimal number (base 10).
Step 2: Convert the decimal number so obtained to the new base number.
Example 3.15.
5455 = ?4
Solution:
Step 1: Convert from base 6 to base 10
545 = 5 x 62 + 4 x 61 + 5 x 6°
=5x36+4x6+5x1
= 180 + 24 + 5
= 20910
Example 3.16 illustrates the method of converting a number from binary to octal. Similarly,
Example 3.17 shows how to convert a number from binary to hexadecimal. However, these are
lengthy procedures and shortcut methods can be used when we desire such conversions. These
shortcut methods are described below.
Step 1: Divide the binary digits into groups of three (starting from the right).
Step 2: Convert each group of three binary digits to one octal digit. Since there are only 8 digits (0
to 7) in the octal number system (refer to Figure 3.1), 3 bits (23 = 8) are sufficient to represent any
octal number in binary. Since decimal digits 0 to 7 are equal to octal digits 0 to 7, binary to decimal
conversion can be used in this step.
Example 3.18.
1011102 = ?8
Solution:
Step 1: Divide the binary digits into groups of 3 starting from right (LSD).
101 110
Step 2: Convert each group into one digit of octal (use binary-to-decimal conversion).
1012=lx22 + 0x21 + lx2°
=4+0+1
= 58
1102= Ix22+1 x2'+0x2°
=4+2+0 = 68
Hence, 1011102 = 568
Compare the result with the result of Example 3.16.
Example 3.19.
11010102 = ?8 Solution:
1101010a =001 101 010 (Group of 3 digits from right)
= 1528 (Convert each group to an octal digit) Hence, 11010102 = 1528
Example 3.20.
5628 = ?2
Solution:
Step 1: Convert each octal digit to 3 binary digits.
58=1012
68=1102
28= 0102
Example 3.23.
101101011002 = ?16
Solution:
Step 1 : Divide the binary digits into groups of 4.
1101 0011
Step 2: Convert each group of 4 binary digits to 1 hexadecimal digit.
11012 -=-1 x 23 + 1 x 22 + 0 x 21 + 1 x 2°
=8+4+0+1
= 1310
= D16
00112 = 0 x 23 + 0 x 22 + 1 x 21 + 1 x 2°
=0+0+2+1 = 316
Hence, 110100112
= D316
Compare the result with the result of Example 3.17.
Example 3.24.
2AB16 = ?2
Solution:
Step 1: Convert the decimal equivalent of each hexadecimal digit to 4 binary digits.
216 = 210 = 00102
A16=10I0 =10102
B16=ll10 =l0ll2
Figure 3.2 summarizes the relationship between the decimal, binary, hexadecimal, and octal
number systems. Note that the maximum value for a single digit of octal (7) is equal to the
maximum value of three digits of binary. The value range of one digit of octal duplicates the value
range of three digits of binary. If octal digits are substituted for binary digits, the substitution is on
a one-to-three basis. Thus, computers that print octal numbers instead of binary, while taking
memory dump, save one-third of the printing space and time.
Decimal Hexadecimal Binary Octal
0 0 0 0
1 1 1 1
2 2 10 2
3 3 11 3
4 4 100 4
5 5 101 5
6 6 110 6
7 7 111 7
8 8 1000 10
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111
16 10 10000
Figure 3.2. Relationship among Decimal, Binary, Hexadecimal and Octal number systems.
Similarly, note that the maximum value of one digit in hexadecimal is equal to the maximum value
of four digits in binary. Thus, the value range of one digit of hexadecimal is equivalent to the
value range of four digits of binary. Therefore, hexadecimal shortcut notation is a one-to-four
reduction in the space and time required for memory dump.
FRACTIONAL NUMBERS
In binary number system, fractional numbers are formed in the same general way as in the decimal
number system. For example, in the decimal number system,
0.235 = (2 x 10"') + (3 x 10"2) + (5 x 10"3) and
68.53 = (6 x 10') + (8x 10°) +(5 + (3 x 10"2)
Similarly, in the binary number system,
0.101 =(1 x2"') + (0x2"2) 10.01 =(1 x21) + <0x2°) + x2"3)and
10.01 = (1x21) + (0x20) + 0x1-1) + (1x2-2)
Thus, the binary point serves the same purpose as the decimal point. Some of the positional values
in the binary number system are given below.
In general, a number in a number system with base b would be written as: an an.i... ao. a.i a_2... a.m
and would be interpreted to mean an x bn + an., x b"'1 + ... + ao x b° + a4 x b"1 + a.2 x b"2 + .;. + a.m
x b"m
The symbols an, an.h ..., a.m used in the above representation should be one of the b symbols allowed
in the number system.
Thus, as per the above mentioned general rule,
46.328 = (4 x 81) + (6 x 8°) + (3 x 8'1) + (2 x 8"2) and
5A.3C16 = (5 x 161) + (A x 16°) + (3 x 16"1) + (C x 16"2)
Example 3.26.
Find the decimal equivalent of the binary number 110.101
Solution:
110.1012 = 1 x22+ 1 x2' + 0x2° + 1 x2" 0 x 2"1 +
0x2-2 + 1 x 2-3
= 4 + 2 + 0 + 0.5 + 0 + 0.125
= 6 + 0.5 + 0.125
= 6.62510
Points to Remember
Questions
1. What is the difference between positional and non-positional number systems? Give examples
of both types of number systems.
2. What is meant by the base of a number system? Give examples to illustrate the role of base
in positional number systems.
3. What is the value of the base for decimal, hexadecimal, binary and octal number systems?
4. Give an example for octal number system to show that the same digit may signify different
values depending on the position it occupies in the number.
5. What will be the total number of different symbols or digits and the maximum value of a
single digit for the following number systems:
(a) Number system with base 5
(b) Number system with base 20
(c) Number system with base 9
(d) Number system with base 12
6. What is a 'bit' in computer terminology? How many different patterns of bits are possible with
(a) 6 bits
(b) 7 bits
(c) 8 bits
7. Explain the meaning of the term "memory dump".
8. Why are octal and/or hexadecimal number systems used as shortcut notation?
9. Find out the decimal equivalent of the following binary numbers:
(a) 1101011 (f) 1000
(b) 11010 (g) 10110001100
(c) 10110011 (h) 1010101100
(d) 11011101 (i) 110001
(e) 1110101 (j) 111
10. Find out the octal equivalent of the binary numbers of Question 9.
11. Find out the hexadecimal equivalent of the binary numbers of Question 9.
12. Convert the following numbers to decimal numbers:
(a) 1101102 (c) 2A3B16
(b) 25736 (d) 12349
13. Convert the following decimal numbers to binary numbers:
(a) 43510 (c) 3210
(b) 169410 (d) 135,o
14. Convert the decimal numbers of Question 13 to octal numbers.
15. Convert the decimal numbers of Question 13 to hexadecimal numbers.
16. Carry out the following conversions:
(a) 1256 = ?4
(b) 249 = ?3
(c) ABC16 = ?8
17. Convert the following numbers to their binary equivalent:
(a) 2AC16 (c) 26148
(b) FAB16 (d) 5628
18. Find the decimal equivalent of the following numbers:
(a) [Link] (c) 247.658
(b) 1001.0112 (d) A2B.D416
Chapter 4
Computer Codes
In the previous chapter we have discussed about true or "pure" binary numbers. In this chapter we
will see how these binary numbers are coded to represent characters in computers. Thus the goal
of this chapter is to present the formats used in computers to record data. Although many coding
schemes have been developed over the years, we will be discussing only the most commonly used
computer codes.
Numeric data is not the only form of data that is to be handled by a computer. We often require to
process alphanumeric data also. An alphanumeric data is a string of symbols where a symbol may
be one of the letters A, B, C, ..., Z or one of the digits 0, 1,2, ..., 9 or a special character, such as+
-*/,.() = (space or blank) etc. An alphabetic data consists of only the letters A, B, C, ..., Z and the
blank character. Similarly, numeric data consists of only numbers 0, 1,2, ..., 9. However, any data
must be represented internally by the bits 0 and 1. As such, binary coding schemes are used in
computers to represent data internally. In binary coding, every symbol that appears in the data is
represented by a group of bits. The group of bits used to represent a symbol is called a byte. To
indicate the number of bits in a group, sometimes a byte is referred to as "n-bit byte" where the
group contains n bits. However, the term byte is commonly used to mean an 8-bit byte (a group of
8 bits) because most of the modern computers use 8 bits to represent a symbol.
BCD CODE
The Binary Coded Decimal (BCD) code is one of the early memory codes. It is based on the idea
of converting each digit of a decimal number into its binary equivalent rather than converting the
entire decimal value into a pure binary form. This facilitates the conversion process to a great
extent.
The BCD equivalent of each decimal digit is shown in Figure 4.1. Since 8 and 9 require 4 bits, all
decimal digits are represented in BCD by 4 bits. You have seen in Example 3.9 that 42i 0 is equal
to IOIOIO2 in a pure binary form. Converting 42i0 into BCD, however, produces the following
result:
4210 = 0100/4 0010/2 or 01000010 in BCD
Decimal Digits BCD Equivalent
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
Figure 4.1. BCD equivalent of decimal digits.
Note that each decimal digit is independently converted to a 4 bit binary number and hence, the
conversion process is very easy. Also note that when 4 bits are used, altogether 16 (24)
configurations are possible (refer to hexadecimal number system). But from Figure 4.1 you can
see that only the first 10 of these combinations are used to represent decimal digits. The remaining
6 arrangements (1010, 1011, 1100, 1101, 1110 and 1111) have decimal values from 10 to 15.
These arrangements are not used in BCD coding. That is, 1010 does not represent lO,o in BCD.
Instead,
In the above discussion, we have used a group of 4 bits to represent a digit (character) in BCD. 4-
bit BCD coding system can be used to represent only decimal numbers because 4 bits are
insufficient to represent the various characters used by a computer. Instead of using 4 bits with
only 16 possible characters, computer designers commonly use 6 bits to represent characters in
BCD code. In the 6-bit BCD code, the four BCD numeric place positions are retained, but two
additional zone positions are added. With 6 bits, it is possible to represent 64 (26) different
characters. This is a sufficient number to code the decimal digits (10), alphabetic letters (26), and
other special characters (28). Figure 4.2 illustrates the coding of alphabetic and numeric characters
in BCD.
In Chapter 3 we have seen the use of octal and hexadecimal number systems as shortcut notations
for binary. Because BCD is a 6-bit code, it can be easily divided into two 3-bit groups. Each of
these 3-bit groups can be represented by 1 octal digit. Thus octal number system is used as shortcut
notation for memory dump by computers that use BCD code for internal representation of
characters. This results in a one-to-three reductions in the volume of memory dump. Figure 4.2
also shows the octal equivalent of the alphabetic and numerical characters coded in BCD.48
I Foundations of Computing
Character BCD Code Octal Equivalent
Zone Digit
A 11 0001 61
B 11 0010 62
C 11 0011 63
D 11 0100 64
E 11 0101 65
F 11 0110 66
G 11 0111 67
H 11 1000 70
I 11 1001 71
J 10 0001 41
K 10 0010 42
L 10 0011 43
M 10 0100 44
N 10 0101 45
O 10 0110 46
P 10 0111 47
Q 10 1000 50
R 10 1001 51
S 01 0010 22
T 01 0011 23
U 01 0100 24
V 01 0101 25
W 01 0110 26
X 01 0111 27
Y 01 1000 30
Z 01 1001 31
1 00 0001 01
2 00 0010 02
3 00 0011 03
4 00 0100 04
5 00 0101 05
6 00 0110 06
7 00 0111 07
8 00 1000 10
9 00 1001 11
0 00 1010 12
Figure 4.2. Alphabetic and numeric characters in BCD along with their Octal equivalent. Chapter
4 ■ Computer Codes
Example 4.1.
Show the binary digits used to record the word BASE in BCD.
Solution:
B = 110010 in BCD binary notation
A = 110001 in BCD binary notation
S = 010010 in BCD binary notation
E = 110101 in BCD binary notation
Example 4.2.
Using octal notation, show the BCD coding for the word DIGIT.
Solution:
D = 64 in BCD octal notation
I = 71 in BCD octal notation
G = 67 in BCD octal notation
I = 71 in BCD octal notation
T = 23 in BCD octal notation
So the BCD coding for the word DIGIT in octal notation will be
64/D
21/I
67/G
21/I
23/T
EBCDIC
The major problem with BCD code is that only 64 (26) different characters can be represented in
it. This is not sufficient for providing decimal numbers (10), lower-case letters (26), capital letters
(26), and a fairly large number of other special characters (28+).
Hence, the BCD code was extended from a 6-bit code to an 8-bit code. The added 2 bits are used
as additional zone bits, expanding the zone to 4 bits. The resulting code is called the Extended
Binary-Coded Decimal Interchange Code (EBCDIC). In this code it is possible to represent 256
(28) different characters instead of 64 (26). In addition to the various character requirements
mentioned above, this also allows a large variety of printable characters and several nonprintable
control characters. The control characters are used to control such activities as printer vertical
spacing, movement of cursor on the terminal screen, etc. All of the 256 bit combinations have not
yet been assigned characters, so the code can still grow as new requirements develop.
Because EBCDIC is an 8-bit code, it can be easily divided into two 4-bit groups. Each of these 4-
bit groups can be represented by 1 hexadecimal digit (refer to Chapter 3). Thus, hexadecimal
number system is used as shortcut notation for memory dump by computers that use EBCDIC for
internal representation of characters. This results in a one-to-four reduction in the volume of
memory dump. Figure 4.3 shows the alphabetic and numerical characters in EBCDIC along with
their hexadecimal equivalent.
Developed by IBM, EBCDIC code is used in most IBM models and in many other computers.
Character EBCDIC Code Hexadecimal Equivalent
Zone Digit
A 1100 0001 Cl
B 1100 0010 C2
C 1100 0011 C3
D 1100 0100 C4
E 1100 0101 C5
F 1100 0110 C6
G 1100 0111 C7
H 1100 1000 C8
I 1100 1001 C9
J 1101 0001 Dl
K 1101 0010 D2
L 1101 0011 D3
M 1101 0100 D4
N 1101 0101 D5
O 1101 0110 D6
P 1101 0111 D7
Q 1101 1000 D8
R 1101 1001 D9
S 1110 0010 E2
T 1110 0011 E3
U 1110 0100 E4
V 1110 0101 . E5
w 1110 0110 E6
X 1110 0111 E7
Y 1110 1000 E8
z 1110 1001 E9
0 1111 0000 F0
1 1111 0001 Fl
2 1111 0010 F2
3 1111 0011 F3
4 1111 0100 F4
5 1111 0101 F5
6 1111 0110 F6
7 1111 0111 F7
8 1111 1000 F8
9 1111 1001 F9
Figure 4.3. Alphabetic and numeric characters in EBCDIC along with their Hexadecimal
equivalent.
From Figure 4.3 it can be observed that in the EBCDIC code, the digit values are the same as the
numeric characters - 0 through 9 (0000 - 1001). But numeric values need some special
consideration because we must have a way of indicating whether the number is positive, negative,
or unsigned (implies positive). Thus, when a numeric value is represented in EBCDIC, a sign
indicator is used in the zone position of the rightmost digit. A sign indicator of hexadecimal C is
a plus sign, hexadecimal D is a minus sign, and hexadecimal F means the number is unsigned.
Figure 4.4 illustrates the representation of numeric values in EBCDIC. Note that the only zone
affected by the sign is the* zone of the rightmost digit. All other zones remain as F, the zone value
for numeric characters in EBCDIC. Because each decimal digit has a zone with it, numbers coded
in EBCDIC are called zoned decimal numbers. Numeric data input into the computer are usually
zoned decimal numbers. Printers can print only those numeric characters that are in a zoned-
decimal format.
However, most computers cannot perform arithmetic operations on zoned-decimal data. Thus,
before any arithmetic operation can be performed, the data must be converted to a format on which
arithmetic operations are possible. One such acceptable format is the packed decimal format. The
following steps are used to convert a zoned decimal nunoer to a packed decimal number:
Step 1: The zone half and the digit half of the rightmost byte are reversed. This moves the sign
to the extreme right of the number.
Step 2: All remaining zones are dropped out. Figure 4.5 illustrates the conversion process of zoned
decimal data to packed data.
Numeric Value Zoned Format Packed Format
It may be observed that packed data requires fewer number of bytes (group of 8 bits) as compared
to zoned data. In the zoned format, there is only one digit per byte (each digit along with the zone
requires 8 bits). But there are two digits in each byte in the packed format (each digit requires 4
bits). If the packing process does not completely fill a byte, it is filled with a zero. For example,
the zoned data F3F4F5F6 will convert to packed data 03456F. Observe that in this example, the
zoned data requires 4 bytes and the packed data requires only 3 bytes
Example 4.3.
Using binary notation, write the EBCDIC coding for the word BIT. How many bytes are required
for this representation?
Solution:
B = 1100 0010 in EBCDIC binary notation
I = 1100 1001 in EBCDIC binary notation
T = 1110 0011 in EBCDIC-binary notation
So the EBCDIC coding for the word BIT in binary notation will be
11000010/B 11001001/I 11100011/T
3 bytes will be required for this representation because each letter requires 1 byte (or 8 bits).
Example 4.4.
Write the EBCDIC coding for the word ZONE (use hexadecimal notation). How many bytes will
be required for this representation?
Solution:
Z = E9 in EBCDIC hexadecimal notation
O = D6 in EBCDIC hexadecimal notation
N = D5 in EBCDIC hexadecimal notation
E = C5 in EBCDIC hexadecimal notation
So the EBCDIC coding for the word ZONE in hexadecimal notation will be
E9/Z D6/O D5/N C5/E
Each hexadecimal digit requires 4 bits and there are altogether 8 hexadecimal digits. So in all 8 x
4 = 32 bits or 4 bytes (8 bits = 1 byte) will be required for this representation. . >
We may also write directly that since each letter requires 1 byte for its representation in EBCDIC
and there are 4 letters in the word ZONE, 4 bytes will be required for this representation.
Example 4.5.
Write the EBCDIC zoned-decimal coding for the value +256 (use hexadecimal). How many bytes
will be required for this representation?
Solution:
+256 = F2F5C6 in EBCDIC
Each hexadecimal digit requires 4 bits and there are altogether 6 hexadecimal digits. So in all 6 x
4 = 24 bits or 3 bytes (8 bits = 1 byte) will be required for this representation.
We may also write directly that since each digit requires 1 byte for its representation in the
EBCDIC zoned decimal coding and there are 3 digits in the given number, 3 bytes will be required
for this representation.
Example 4.6.
Write -128 as packed decimal number (use hexadecimal). How many bytes will be required for
this representation?
Solution:
-128 = F1F2D8 in EBCDIC
= 128D in packed format
Each hexadecimal digit requires 4 bits and there are altogether 4 hexadecimal digits. So in all 4 x
4 = 16 bits or 2 bytes (1 byte = 8 bits) will be required for this representation.
ASCII
Another computer code that is very widely used is the American Standard Code for Information
Interchange (ASCII). ASCII has been adopted by several American computer manufacturers as
their computers' internal code. This code is popular in data communications, is used almost
exclusively to represent data internally in microcomputers, and is frequently found in the larger
computers produced by some vendors.
ASCII is of two types - ASCII-7 and ASCII-8. ASCII-7 is a 7-bit code that allows 128 (27) different
characters. The first 3 bits are used as zone bits and the last 4 bits indicate the digit.
Microcomputers using 8-bit byte (group of 8 bits for 1 byte) use the 7-bit ASCII by leaving the
leftmost first bit of each byte as a zero. Figure 4.6 shows the alphabetic and numeric characters in
ASCII-7 notation.
ASCII-8 is an extended version of ASCII-7. It is an 8-bit code that allows 256 (28) different
characters rather than 128. The additional bit is added to the zone bits. Figure 4.7 shows the
alphabetic and numeric characters in ASCII-8 notation. Observe that other than the zone-value
differences, ASCII-7 and ASCII-8 are identical. ASCII also uses hexadecimal as its four-to-one
shortcut notation for memory dump. Figures 4.6 and 4.7 also show the hexadecimal equivalent of
the ASCII notations.
Example 4.7.
Write the binary coding for the word BOY in ASCII-7. How many bytes are required for this
representation?
A 100 0001 41
B 100 0010 42
C 100 0011 43
D 100 0100 44
E 100 0101 45
F 100 0110 46
G 100 0111 47
H 100 1000 48
I 100 1001 49
J 100 1010 4A
K 100 1011 4B
L 100 1100 4C
M 100 1101 4D
N 100 1110 4E
O 100 1111 4F
P 101 0000 50
Q 101 0001 51
R 101 0010 52
S 101 0011 53
T 101 0100 54
U 101 0101 55
V 101 0110 56
W 101 0111 57
X 101 1000 58
Y 101 1001 59
Z 101 1010 5A
0 0101 0000 50
1 0101 0001 51
2 0101 0010 52
3 0101 0011 53
4 0101 0100 54
5 0101 0101 55
6 0101 0110 56
7 0101 0111 57
8 0101 1000 58
9 0101 1001 59
A 1010 0001 Al
B 1010 0010 A2
C 1010 0011 A3
D 1010 0100 A4
E 1010 0101 A5
F 1010 0110 A6
G 1010 0111 A7
H 1010 1000 A8
I 1010 1001 A9
J 1010 1010 AA
K 1010 1011 AB
L 1010 1100 AC
M 1010 1101 AD
N 1010 1110 AE
O 1010 mi AF
P 1011 0000 B0
Q 1011 0001 Bl
R 1011 0010 B2
S 1011 0011 B3
T 1011 0100 B4
U 1011 0101 B5
V 1011 0110 B6
W 1011 0111 B7
X 1011 1000 B8
Y 1011 1001 B9
Z 1011 1010 BA
Figure 4.7. Numeric and alphabetic characters in ASCII-8 notation along with their Hexadecimal
equivalent.
Solution:
B = 1000010 in ASCII-7 binary notation
O = 1001111 in ASCII-7 binary notation
Y = 1011001 in ASCII-7 binary notation
Hence, the binary coding for the word BOY in ASCII-7 will be
1000010/B 1001111/O 1011001/Y
Since each character in ASCII-7 requires one byte for its representation and there are 3 characters
in the word BOY, 3 bytes will be required for this representation.
Example 4.8.
Write the hexadecimal coding for the word GIRL in ASCII-7. How many bytes are required for
this representation?
Solution:
G = 47 in ASCII-7 hexadecimal notation
I = 49 in ASCII-7 hexadecimal notation
R = 52 in ASCII-7 hexadecimal notation
L = 4C in ASCII-7 hexadecimal notation
Hence, the hexadecimal coding for the word GIRL in ASCII-7 will be
47/G 49/I 52/R 4C/L = GIRL
Since each character in ASCII-7 requires one byte for its representation and there are 4 characters
in the word GIRL, 4 bytes will be required for this representation.
Example 4.9.
Write the binary coding for the word SKY in ASCII-8. How many bytes are required for this
representation?
Solution:
S = 10110011 in ASCII-8 binary notation
K = 10101011 in ASCII-8 binary notation
Y = 10111001 in ASCII-8 binary notation
Hence, the binary coding for the word SKY in ASCII-8 will be
10110011/S 10101011/K 10111001/Y = SKY
Since each character in ASCII-8 requires one byte for its representation and there are 3 characters
in the word SKY, 3 bytes will be required for this representation.
Example 4.10.
Write the hexadecimal coding for The word STAR in ASCII-8. How many bytes are required for
this representation?
Solution:
S = B3 in ASCII-8 hexadecimal notation
T = B4 in ASCII-8 hexadecimal notation
A = Al in ASCII-8 hexadecimal notation
R = B2 in ASCII-8 hexadecimal notation
Hence, the hexadecimal coding for the word STAR in ASCII-8 will be
B3/S B4/T A1/A B2/R = STAR
Since each character in ASCII-8 requires one byte for its representation and there are 4 characters
in the word STAR, 4 bytes will be required for this representation.
COLLATING SEQUENCE
The value of an alphanumeric or alphabetic data element is usually the name of some object.
Obviously one would not like to perform any arithmetic on such data but one may like to compare
them in order to arrange them in some desired sequence. Now, if we compare the alphabetic values
A and B, which one will be treated as greater by the computer? For an answer to such questions,
it is necessary to have some assigned ordering among the characters used by the computer. This
ordering is known as the collating sequence.
Collating sequence may vary from one computer system to another depending on the type of
computer code used by a particular computer. To illustrate this, let us consider the computer codes
already discussed in this chapter. Observe from Figures 4.2 and 4.3 that the zone values of the
characters A through 9 decrease in BCD code from the equivalent of decimal 3 down to 0, while
the zone values of the characters A through 9 increases in EBCDIC from the equivalent of decimal
12 to 15. This means that a computer, which uses BCD code for its internal representation of
characters will treat alphabetic characters (A, B, ..., Z) to be greater than numeric characters (0,
1, ..., 9). On the other hand, a computer, which uses EBCDIC for its internal representation of
characters will treat numeric characters to be greater than alphabetic characters. Similarly, observe
from Figure 4.6 and 4.7 that a computer, which uses ASCII for its internal representation of
characters will place numbers ahead of letters during a sort (ascending) because the number
characters have a zone value that is less than the zone value for letters.
However, whatever may be the type of computer code used, in most (not all - in BCD 0 > 9)
collating sequences, the following rules are observed:
1. Letters are considered in alphabetic order (A < B < C < ... <Z)
2. Digits are considered in numeric order (0 < 1 < 2 < ... <9).
Example 4.11.
Suppose a computer uses EBCDIC as its internal representation of characters. In which order will
this computer sort the strings 23, Al, 1A?
Solution:
In EBCDIC, numeric characters are treated to be greater than alphabetic characters. Hence, in the
said computer, the numeric characters will be placed after the alphabetic characters and the given
string will be treated as:
Al <1A<23
Therefore, the sorted sequence will be: Al, 1A, 23.
Example 4.12
Suppose a computer uses ASCII for its internal representation of characters. In which order will
this computer sort the strings 23, Al, 1A?
Solution:
In ASCII, nuirieric characters are treated to be less than alphabetic characters. Hence, in the said
computer, the numeric characters will be placed before the alphabetic characters and the given
string will be treated as:
23<1A<A1 Therefore, the sorted sequence will be: 23, 1 A, Al.
Points To Remember
1. Binary coding schemes are used in computers to represent data internally. In binary coding,
every symbol that appears in the data is represented by a group of bits. The group of bits used to
represent a symbol is called a byte. Most modern computers use 8 bits to represent a symbol.
Hence the term byte is commonly used to mean a group of 8 bits.
2. The commonly used computer codes for internal representation of data are BCD, EBCDIC
and ASCII.
3. BCD {Binary Coded Decimal) is a 6-bit code, which can represent 64 different characters.
Because BCD is a 6-bit code, it can be easily divided into two 3-bit groups. Each of these 3-bit
groups can be represented by 1 octal digit. Thus octal number system is used as shortcut notation
for memory dump by computers that use BCD code for internal representation of characters.
4. EBCDIC {Extended Binary-Coded Decimal Interchange Code) is an 8-bit code, which can
represent 256 different characters. Because EBCDIC is an 8-bit code, it can be easily divided into
two 4-bit groups. Each of these 4-bit groups can be represented by 1 hexadecimal digit. Thus,
hexadecimal number system is used as shortcut notation for memory dump by computers that use
EBCDIC for internal representation of characters.
5. ASCII (American Standard Code for Information Interchange) is one of the most popular
computer codes. It is of two types - ASCII-7 and ASCII-8. ASCII-7 is a 7-bit code, which can
represent 128 different characters and ASCII-8 is an 8-bit code, which can represent 256 different
characters. Computers, which use ASCII-7 and group of 8 bits for a byte leave the leftmost first
bit of each byte as a zero. ASCII also uses hexadecimal as its four-to-one shortcut notation for
memory dump.