Chapter 4
Chapter 4
DATA REPRESRNTAION
AND
NUMBER SYSTEMS
1
DATA REPRESENTATION AND NUMBER SYSTEMS
2
Number system
• A number system defines a set of values used to represent
quantity. Today the most common number system in use is
Arabic system.
• The number systems can be categorized in to two broad
categories: Positional number systems & Non-positional
number systems.
• Non-Positional number systems: - is a method of counting on
fingers. It was very difficult to perform arithmetic with such a
number system, as it had no symbol for zero.
• Positional number systems: - the value of each digit in a
number is defined not only by the symbol but also by the
symbol’s position. They have a base or radix.
3
Number system
Base (or radix): - tells the number of symbols used in the system.
Modern computers use the radix 2 because they recognize only two symbols,
which are represented in digital circuits as 0s and 1s.
• The base of a number system is indicated by a subscript (decimal number)
and this will be followed by the value of the number.
For example (7592) 10 is of base 10 number system.
(1010) 2 is of base 2 number system.
• Note: For a computer, everything is a number whether it may be numbers,
alphabets, punctuation marks etc.
• Eventually, the number systems that can are generally used by the
computers are:
Decimal system
Binary system
Octal system
Hexadecimal system
4
Number system
Number system Radix value Set of Digits Example
6
2. Binary Number System
• Computers do not use the ten digits of the decimal system for
counting and arithmetic.
• Their CPU and Memory are made up of millions of tiny
switches that can be either in the ON or OFF states.
• The number system with only two digits (0 & 1) is called
Binary number system.
• The place value of the binary number system is based on the
number two.
• In the binary number system with base 2, the weight of nth bit
of the number from Right Hand Side (RHS) is nth bit x 2n-1
7
3. Octal Number System
• It is a base 8 system. It uses powers of 8 to determine the
digit of numbers position.
• Binary octal comparison
• Octal to Binary Binary to Octal
2 3 5
010 011 101
010 011 101
2 3 5
8
Number system
Binary-Decimal-Octal Comparison
Binary Number Decimal Number Octal Number
000 0 0 (0 x 80)
001 1 1 (1 x 80)
010 2 2 (2 x 80)
011 3 3 (3 x 80)
100 4 4 (4 x 80)
101 5 5 (5 x 80)
110 6 6 (6 x 80)
111 7 7 (7 x 80)
1000 8 10 (1 x 81 + 0 x 80)
1001 9 11 (1 x 81 + 1 x 80)
1010 10 12 (1 x 81 + 1 x 80) 9
4. Hexadecimal Number System
• Hexadecimal number system has the base (radix) 16.
• Each hexadecimal number represents a power of 16.
• To represent the decimal numbers, this system uses 0-9
numbers and A to F characters to represent 10 to 15,
respectively.
10
Number system
Decimal-Hexadecimal-Binary Comparison
Decimal Hex Binary
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
11
13 D 1101
Conversion between Number Systems
1. Conversion of Decimal to Binary:
Follow the following steps to convert decimals in to binary.
1. Begin by dividing the decimal number by 2 (the base of binary number).
2. Note the remainder separately as the right most digit of the binary
equivalent.
3. Continually repeat the process of dividing by 2 until the quotient is zero.
4. Finally, when no more division can occur, write down the remainders in
reverse order (last remainder written first).
12
Conversion between Number Systems
Eg. Determine the binary equivalent of (36) 10
13
Conversion between Number Systems
2. Conversion of Binary to Decimal:
In this case, each digit of the binary number is multiplied by its
weighted position and each of the weighted values is added together to
get the decimal number.
Eg determine the decimal equivalent of (11010) 2
(11010) 2 = (1 x 24) + (1 x 23) + (0 x 22) + (1 x 21) + (0 x 20)
= 16 + 8 + 0 + 2 + 0
= (26) 10
14
Conversion between Number Systems
3. Conversion of Binary fractions to Decimal:
here we use the negative exponents, to denote the negative powers of
two.
Eg. Determine the decimal equivalent of (0.01101) 2
(0.01101) 2 = (0 x 2-1) + (1 x 2-2) + (1 x 2-3) + (0 x 2-4) + (1 x 2-5)
= 0 + ¼ + 1/8 + 0 + 1/32
= 0 + 0.25 + 0.125 + 0 + 0.03125
= (0.40625) 10
15
Conversion between Number Systems
4. Conversion of Decimal to Octal:
Here the same procedure is adopted as in decimal to binary conversion
but the decimal number is divided by 8 (the base of the octal system).
• Eg. Determine the octal equivalent of (359) 10
16
Conversion between Number Systems
5. Conversion of Decimal fraction to Octal fractions:
The steps we have to follow in this case are:-
1. Multiply the decimal fraction by 8 (the base of the octal system).
2. If the whole number is generated, record the whole number, otherwise place 0.
3. Repeat the above 1st and 2nd steps with the decimal fractions until it becomes.
4. Finally, when no more multiplication can occur, write down the remainders in the downward
direction.
5. In this whole conversion, the first carry produced is the MSB while the last carry is the LSB.
Eg. Determine the octal equivalent of (0.3125) 10.
0.3125 x 8 = 2.5 2
0.5 x 8 =4.0 4
So, (0.3125) 10 = (0.24) 8
Note: In some circumstances of changing the decimal fraction to octal fractions the conversion may not
end. In such cases you have to take the approximate of 8 bits.
17
Conversion between Number Systems
6. Conversion of octal to Decimal:
Here each digit of octal number is multiplied by its weighted position,
and each of the weighted values are added together to get the decimal
number.
Eg. Determine the decimal equivalent of (456)8.
456) 8 = (4 x 82) + (5 x 81) + (6 x 80)
= 256 + 40 + 6
= (302) 10
18
Conversion between Number Systems
7. Conversion of Octal fractions to Decimal fractions:
Steps followed here are:
1. Write the weight value of each bit of the octal fractional number.
2. Multiply the weighted position with the respective bit of the octal fractional
number.
3. Add all the weighted values to get the decimal number.
Eg. Determine the decimal equivalent of (237.04) 8.
(237.04) 8 = (2 x 82) + (3 x 81) + (7 x 80) + (0 x 8-1) + (4 x 8-2)
= (2 x 64) + (3 x 8) + (7 x 1) + (0) + (4 x 1/64)
= 128 + 24 + 7 + 0 + 0.0625
= (159.0625) 10 19
Conversion between Number Systems
8. Conversion of Binary to Octal:
steps that are followed here are:
1. Break the binary number in to 3-bit sections starting from the LSB to the MSB.
2. Convert the 3-bit binary number to its octal equivalent.
• For whole numbers, it may be necessary to add a zero as the MSB in order to complete a grouping
of three bits.
20
Conversion between Number Systems
9. Conversion of Octal to Binary:
The following steps are used here: -
1. Convert the octal digit to its 3-bit binary equivalent.
2. Combine the 3-bit sections by removing the spaces to get the binary.
E.g. determine the binary equivalent of (231) 8
21
Conversion between Number Systems
10. Conversion of Decimal to Hexadecimal:
To convert a decimal number into its hexadecimal equivalent, the same procedure
is adopted as decimal to binary but the decimal number is divided by 16 (the base
of the hexadecimal number system).
E.g. determine the hexadecimal equivalent of (5112) 10.
22
Conversion between Number Systems
11. Conversion of Decimal fractions to Hexadecimal fractions:
To perform this operation we follow the following steps.
1. Multiply the decimal fraction by 16 (the base of the hexadecimal system).
2. If a whole number is generated, record the whole number otherwise place 0.
3. Repeat steps 1 and 2 with decimal fraction until it becomes 0.
4. Finally, when no more multiplication can occur, write down the remainders in the
down ward direction.
E.g. determine the hexadecimal equivalent of (0.625) 10
23
Conversion between Number Systems
12. Conversion of Hexadecimal to Decimal:
In this case, each digit of the hexadecimal number is multiplied by its
weighted position and each weighted values are added together to get
the decimal number.
E.g. determine the decimal equivalent of (B14) 16.
(B14) 16 = (B x 162) + (1 x 161) + (4 x 160)
= (11 x 256) + (16) + (4)
= (2836)10
24
Conversion between Number Systems
13. Conversion of hexadecimal fractions to Decimal fractions:
steps
1. Write the weighted value of each bit of the hexadecimal fractional number.
2. Multiply the weighted position with the respective bit of the hexadecimal
fractional number.
3. Add all the weighted values to get the decimal number.
E.g. determine the decimal equivalent of (A.23) 16
(A.23) 16 = (A x 160) + (2 x 16-1) + (3 x 16-2)
=10 + 0.125 + 0.01171875
= (10.13671875)10
25
Conversion between Number Systems
14. Conversion of Binary to hexadecimal:
Steps
1. Break the binary number into 4-bit sections starting from the LSB to
the MSB.
2. Convert the 4-bit binary number to its hexadecimal equivalent.
E.g. determine the hexadecimal equivalent of (11001011) 2.
26
Conversion between Number Systems
15. Conversion of Hexadecimal to Binary:
Steps that are followed here are the following
1. Convert each hexadecimal digit to its 4-bit binary equivalent.
2. Combine the 4-bit sections by removing the spaces to get the binary number.
E.g. determine the binary equivalent of (5AF) 16.
27
Arithmetic System
During school days, arithmetic was restricted only to decimal number
system.
However, in computer, we require arithmetic on other number systems
such as binary, octal and hexadecimal.
1. Binary arithmetic:
Everything that is stored in or manipulated by the computer is a number.
The computer understands the numbers 1 and 0.
The basic arithmetic operations of the binary number system are:
Addition and subtraction.
28
Arithmetic System
I. Binary Addition:
Binary addition is carried out in the same way as the decimal addition is performed. There
are four outcomes or rules of the binary addition. These are shown below:
30
Arithmetic System
31
Arithmetic System
2. Octal Arithmetic:
The essential arithmetic operations of the octal number system are:
Addition
Subtraction
32
Arithmetic System
i. Octal Addition:
Addition of the octal number is carried out in the same way as the decimal addition is performed.
The steps are given below:
1. First, add the two digits of the unit column of the octal number in decimal.
2. This process is repeated for each larger significant digit of the octal number.
3. During the process of addition, if the sum is less than or equal to 7, then it can be directly
written as an octal digit.
4. If the sum is greater than 7, then subtract 8 from that particular digit and carry 1 to the next
digit position.
33
Arithmetic System
ii. Octal Subtraction:
In the octal subtraction, the method, which we have adopted, is similar to that of
binary subtraction method. The only difference lies in the carry part.
During octal subtraction instead of 1, we will borrow 8 and the rest of steps are
similar to that of binary subtraction.
E.g. Subtract (667) 8 from (770) 8.
8+6=14
6 6 8 (Borrow)
7 7 0
- 6 6 7
1 0 1 Thus, the difference is (101) 8. 34
Arithmetic System
1.Hexadecimal Arithmetic:
Hexadecimal number system is extensively used in the
memories of the computer system and in the computer
instructions.
The basic arithmetic operations that are to be performed are
listed below:
Addition
Subtraction
35
Arithmetic System
I. Hexadecimal Addition:
The addition operation performed with the hexadecimal numbers is analogous to
the decimal addition except with a few differences that are discussed in the
following steps:
1. First add the unit column of the hexadecimal digits in decimal.
2. This process is repeated for each larger significant digit of the hexadecimal
number.
3. During the process of addition, observe if the sum is 15 or less, then it can be
directly expressed as hexadecimal digit.
If the sum is greater than 15, then subtract 16 from that particular digit and carry
1 to the next digit position. 36
Arithmetic System
E.g. Add the hexadecimal numbers (A27E9) 16 and (6FB43) 16.
1 1 1 1
A 2 7 E 9
+ 6 F B 4 3
1 17 18 19 18 12
-16 -16 -16 -16 -
1 1 2 3 2 12(=C)
Thus the hexadecimal sum is (11232C) 16
37
Arithmetic System
II. Hexadecimal Subtraction:
The hexadecimal subtraction is based on the same principles as of binary
subtraction.
In this subtraction, 16 will be used as borrow instead of 1.
The rest of steps are similar to the binary subtraction.
E.g. Subtract (75) 16 from (527) 16.
4 16+2=18 (Borrow)
5 2 7
- 7 5
4 11 2
4 B 2 (Hex form)
Thus the hexadecimal difference is (4B2) 16.
38