Professional Documents
Culture Documents
NUMBER SYSTEMS
1. Introduction
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 between them.
Definition:
A number system is a set of codes which are given to distinct values or quantities.
Using those assigned codes (symbols), we will 'count'. The symbols are called digits.
Generally, a number system is characterized by:
Base or radix of a number system is the number of digits that are included in the number
system.
b. Its digits
Example 1: A decimal number system is the system that we always use in our day-
To-day activities. As you know this number system contains0,1,2,3,4,5,6,7,8,9 and as a
result its base (number of digits) is 10. Why do we deal with number systems? The
reason is just to understand the operations of computers. Computer operations can be
divided in to two as Arithmetic and Logical. Arithmetic operations are operations
involving arithmetic calculations like addition, subtraction, multiplication and division.
Logical operations are operations that do not directly relate with numbers. They consist
of comparisons. A very simple example of logical expression can be 2>3, Yes/No'. But
whatever the type of operation is, computers understand only 0 and 1.
In early days, human beings counted on fingers. When ten fingers were not adequate,
stones, 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
1
value of a particular number. Since it is very difficult to perform 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) used in this system. 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:
It may also be observed that the same digit signifies different values depending on the
position it occupies in the number. For example,
Thus any number can be represented by using the available digits and arranging them in
various positions. The principles that apply to the decimal system apply in any other
positional number system. It is important only to keep track of the base of the number
system in which we are working.
There are two characteristics of all number systems that are suggested by the value of the
base. In all number systems, 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. The second characteristic is that the maximum value of a single digit is
always equal to one less than the value of the base.
2
2. Commonly Used Number Systems
3
Base: the given base of the number system
Example4: Find the weight of the digits after the decimal point of the following
Number: “0.125”
Solution:
-1 -2 -3 --- Position
0.12 5 -------- Decimal fraction
Weight (l st digit) = 1st digit X 10-1 = 1 x 1o-1 = 1o -1= 0.1
Weight (2nd digit) = 2nd digit X 10-2 = 2 x 1o-2 = 0.02
Number systems are basically of two types: non – positional and positional.
The binary number system is exactly like the decimal 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 in the units (20) position, the second position from the right is the
2’s (21) position and proceeding in this way we have 4’s (2 2) 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
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).
4
Another important point to note is that with 3 bits (positions), only 8 (2 3) different
patterns of 0’s and 1’s are possible and from the table above 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
decimal number in the range 0 to 2 n-1 can be represented in the binary form as an n-bit
number.
Every computers stored 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 the line printer. This print out
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 1s. 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 1s only), two number systems, octal and
hexadecimal, are used as shortcut notation for binary.
In the octal number system the base is 8. So in this system there are only 8 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 a
decimal system 0,1,2,3,4,5,6,7,8,9. The remaining six digits are denoted by A,B,C,D,E,F
representing the decimal values 10,11,12,13,14,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 hexadecimal F has a decimal equivalent value of
15. Thus, largest single digit is F or 15 (one less than the base). Again, each position in a
hexadecimal system represents a power of the base (16). Thus, the decimal equivalent of
the hexadecimal number 1AF (written as 1AF16) is:
5
or (1x256) + (10x16) + (15x1)
or 256 + 160 +15
or 431
Thus 1AF16 = 43110
Observe that since there are only 16 digits in the hexadecimal number system, so 4 bits
(24 = 16) are sufficient to represent any hexadecimal number in binary.
A decimal number might have two parts: integral and fractional parts. So, for converting
a number from the decimal number system into any other number system, separate it into
integer part (left side of the decimal point) and fraction part (right side of the decimal
point). For the integer part, the following procedure is followed:
1. Divide the integral part of the decimal number by the base of the target number
system and note the remainder.
2. Divide the quotient of the previous division by the base of the target number
system and note the remainder.
3. Repeat step 2 till the quotient becomes 0.
4. Arrange the remainders in an order starting with the last division.
5. The number obtained in step 4 is the integer part of the desired number.
1. Multiply the fraction part by the base of the system and note the integer part of the
result.
2. Multiply the fraction part of the previous result by the base of the system and note
the integer part of the result.
3. Repeat step 2 till the fraction part of the result is zero or till the required accuracy
(number of digits after the decimal point) is achieved.
4. Arrange the integer parts in the order starting with first multiplication.
5. The number obtained in step 4 is the fraction part of the desired number.
Example 1
Convert the decimal number 93 into:
a) binary numbers
b) octal numbers
c) hexadecimal number
6
Solution
a) Conversion into a binary number:-
93 / 2, Q = 46, R = 1
46 / 2, Q = 23, R = 0
23 / 2, Q = 11, R = 1
11 / 2, Q = 5, R = 1
5 / 2, Q = 2, R = 1
2 / 2, Q = 1, R = 0
1 / 2, Q = 0, R = 1
93 / 8, Q = 11, R = 5
11 / 8, Q = 1, R = 3
1 / 8, Q = 0, R = 1
Example 2+
Convert 0.125 from decimal to binary
A number in the non- decimal number system is converted into a decimal number by
multiplying each digit in the number by its place value and adding all the products.
7
Example 1
Example 2
Example 3
Convert the binary number 101.01 into a decimal number
Solution:
101.01 = (1 x 22) + (0 x 21) + (1 x 20) + (0 x 2-1) + (1 x 2-2)
= 4 + 0 + 1 + 0 + 0.25
= 5.25
Therefore, (101.01)2 = 5.2510
Converting from a base other than 10 to a base other than 10
The following two steps are used to convert a number from a base other than 10 to a base
other than 10.
Example 1. 5456 = ?4
Solution:
Step 1: Convert from base 6 to base 10
545 = (5 x 62) + (4 x 61) + (5 x 60)
= (5 x 36) + (4 x 6) + (5 x 1)
= 180 + 24 + 5
= 209
Therefore, 5456 = 20910
Step 2: Convert 20910 to base 4
8
209 / 4, Q = 52, R = 1
52 / 4, Q = 13, R = 0
13 / 4, Q = 3, R = 1
3 / 4, Q = 0, R = 3
Step 2: Convert each group of three binary digits into one octal digit. (Refer to Table 3.1
and try to remember that since there are only 8 digits (0 to 7) in the octal number system,
so 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 so binary to decimal conversion can be used in
this step.
Example 1. 1011102 = ?8
Solution:
Step 1: Divide the binary digits into groups of 3 starting from right
101 110
Step 2: Convert each group into one digit of octal (use binary-to-decimal
conversion)
1012 = 1 x 22 + 0 x 21 + 1 x 20
=4+0+1
= 58
1102 = 1 x 22 + 1 x 21 + 0 x 20
=4+2+0
= 68
Hence, 1011102 = 568
Example 2. 11010102 = ?8
Solution:
11010102 = 001 101 010
(Group 3 digits from right)
1528
9
(Convert each group to an octal digit)
Hence, 11010102 = 1528
Shortcut method for octal to binary conversion
Step 1: Convert each octal digit to a 3 digit binary number. (The octal digits may
be treated as decimal for this conversion).
Step 2: Combine all the resulting binary groups (of 3 digits each) into a single binary
number.
Example 1. 5628 = ?2
Solution:
Step 1: Convert each octal digit to 3 binary digits
58 = 1012
68 = 1102
28 = 0102
Step 2: Combine the binary groups
5628 = 101 110 010
5 6 2
Solution:
67518 = 110 111 101 001
6 7 5 1
= 1101111010012
10
Example 1. 110100112 = ?16
Solution:
Step 1: Divide the binary digits into groups of 4.
1101 0011
00112 = 0 x 23 + 0 x 22 + 1 x 21 + 1 x 20
=0+0+2+1
= 316
Hence, 110100112 = D316
Solution:
101101011002 = 0101 1010 1100
(Group 4 digits from right)
=5AC
(Convert each group to hexadecimal digit)
Hence, 101101011002 = 5AC16
Example 1. 2AB16 = ?2
Solution:
Step 1: Convert the decimal equivalent of each hexadecimal digit to 4 binary digits
216 = 210 = 00102
A16 = 1010 = 10102
B16 = 1110 = 0102
Step 2: Combine the binary groups
2AB16 = 0010 1010 1011
2 A B
11
Solution:
ABC16 = 1010 1011 1100
A B C
= 1010101111002
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.
Table 3.2. Relationship between Decimal, Binary, Hexadecimal and Octal Number
Systems
12
3. Data representation
Bit is the smallest unit of data that can be stored in a computer. It is a single bit that
can be stored in a computer. In other words, it is a single bit that can represent two
values; either 0 or 1.
Byte:
Without question, the most important data structure used by the most microprocessor
is the byte. A byte consists of eight bits and is the smallest addressable datum (data
item) in the microprocessor. It is the most important data structure & is used by most
microcomputer. The bits in a byte are numbered from bit zero (b0) through seven (b7)
as follows:
b7 b6 b5 b4 b3 b2 b1 b0
Since a byte contains eight bits, it can represent 2 8, or 256, different values. Generally,
we'll use a byte to represent:
1. unsigned numeric values in the range 0 to 255
2. signed numbers in the range -128 to +127
3. ASCII character codes
4. Other special data types requiring no more than 256 different values. Many data
types have fewer than 256 items so eight bits is usually sufficient.
The Word: a word is a group of bits greater than or equal to 8 bits. There is no fixed
size for a word length. It depends on from computer to computer. Most micro
13
processors & minicomputers are normally byte oriented with word length 8 bits, 16
bits 32 bits & 64 bits.
This is the simplest coding scheme. Originally BCD coding is used four bits to represent
each digit of the decimal number into its binary equivalent rather than converting the
entire decimal value into a pure binary form.
Example: The code of the digit 1 is 0001
The code of the digit 4 is 0100.
The code of the digit 43 is 01000011
Note that each decimal digit is independently converted to a 4 bit binary number.
However 4 bits are insufficient to represent the various characters used by a
computer system. Instead of using 4 bits with only 16 possible characters, computer
designers commonly 6 bits to represent characters in BCD. In the 6 bit BCD code the 4
BCD numeric place positions are retained but additional zone positions are added. With 6
bit, it is possible to represent 64 (2 6) different characters. This is a sufficient number to
code the decimal digits (10), alphabetic letters(26), and other special characters (28).
Note In addition to the four bits that represent the actual data, additional two bits are
used as zone bits. These bits are used to distinguish the actual data represented.
Observe the following example:
Example :
In 6 Bit BCD representation, 0001 is used to represent three characters, letter A, letter J
Or digit 1. How can you distinguish the character represented by 0001? By the zone bits.
The zone bits of the three characters are different. According to the above zone bits,
The digit 1 is represented as 000001. The letter A is represented as 110001. The letter J
is represented as 100001.
14
So the zone bits are determined as11. F is the sixth letter if you count starting from A. So,
it will be represented by the decimal form of the digit which is 110 (or 0110 using 4
digits). Finally, the representation of F in BCD is 110110.
Example: show the binary digits used to record the word BASE in 6 bit BCD code.
Solution:
B = 110010 in BCD binary notation
A = 110001 in BCD binary notation
S = 010010 in BCD binary notation
E = 110101in BCD binary notation
So the binary digits
110010 110001 010010 110101
B A S E
Will record the word BASE in 6 bit BCD.
To make the number of characters represented by BCD more, 2 bits are added to the 6
bits (totally 8 bits). This makes the improved BCD capable of representing 28 (256)
characters. And this coding scheme is called Extended Binary Decimal
Interchange Code (EBCDIC). EBCDIC is developed by IMB; it is an 8 bits pattern. The
only difference between BCD and EBCDIC is their zone bits. Unlike BCD, EBCDIC
uses 4 zone bits and the following table shows you the equivalent zone bits of EBCDIC
to the BCD zone bits.
BCD EBCDIC(zone Letters/Digits
(zone bits of each Represented
bits of group)
each
group)
11 1100 A_I
10 1101 J_R
01 1110 S_Z
00 1111 0_9
In EBCDIC, upper case letters, lower case letters, digits and other printable or non -
Printable characters are included. The limitation of EBCDIC is that, it is not used in any
computer other than IBM machines.
The other popular schemes are ASCII -7 and ASCII-8. ASCII -8 is an extended version
of ASCII-7. Generally, ASCII-7 code was designed as a standard code for ISO
15
(International Organization for Standardization). It is a 7-bit code and as a result
representing 27(128) characters. From the 7-bits, 3-bits are used as zone bits and the other
four bits represent the actual data. ASCII is a little bit different from the BCD and
EBCDIC because in ASCII alphabetical letters are divided into two sections, not three.
100 A_O
101 P_Z
011 0_9
ASCII-8:
ASCII -8 is an extended version of ASCII, which uses 8 bits rather than 7 bits.
ASCII-8 can represent 28(256) possible characters. The difference between ASCII &
ASCII _ 8 is that only on their zone bits. ASCII _ uses 4 bits as a zone bit.
16