Data Representation: Objectives
Data Representation: Objectives
Data Representation: Objectives
CHAPTER 3
DATA REPRESENTATION
OBJECTIVES
To understand representation of data and information
Number systems
Conversions
Basic operations
51
52
Data Representation
eÁw
3.1 Introduction
In digital computers, data and instructions are stored in the computer’s memory using binary code
(or machine code) represented by Binary digIT 's 1 and 0 called BITs. The data may contain digits,
alphabets or special character, which are then converted to bits, understandable by the computer. All
arithmetic operations are performed using binary bits. The study of different number systems is necessary
to understand data representation.
The number system uses well defined symbols called digits. The values of digits depend on the
position in which they appear in the number.
Number systems are basically classified into two types. They are,
1. Non-positional number system.
2. Positional number system.
53
Data Representation
Table 3.1 shows the weightage of the positional values of the decimal number:
Table 3.1
(2)
which can be represented in equivalent
values:
1x24 + 1x23 + 0x22 + 1x21 + 1x20+1x2-1 + 0x2-2 + 1x2-3
Table 3.2 shows the weightage of the positional values of the binary number:
Table 3.2
In the binary number 11010(2) the left most bit 1 is the highest order bit. It is called as the most
significant bit (MSB). Rightmost bit 0 is the lower order bit. It is called least significant bit (LSB).
54
Data Representation
Example 3.3 Consider an octal number 234.56(8) which can be represented in equivalent value as:
eÁw 2x82 + 3x81 + 4x80 + 5x8-1 + 6x8-2
The table 3.3 shows the weightage of the positional values of the octal number:
Table 3.3
The table 3.6 shows the weightage of the positional values of the hexadecimal number:
Table 3.6
55
Data Representation
Example 3.5 Consider the decimal number 53(10) which can be represented in binary as:
56
Data Representation
The table 3.2 shows the weightage of the positional values of the binary number.
eÁw
Weights 24 23 22 21 20 2-1 2-2 2-3
Bits 1 1 0 1 1 1 0 1
Values 16 8 4 2 1 0.5 0.25 0.125
Table 3.2
Example 3.9 Consider an octal number 234.56(8) which can be represented in decimal value as:
2x82 + 3x81 + 4x80 + 5x8-1 + 6x8-2
Table 3.3 below shows the weightage of the positional values of the octal number:
57
Data Representation
Example 3.11 Consider a hexadecimal number 5AF.D (16) which can be represented in decimal
value as:
5x162 + A x 161 + F x 160 + D x 16-1
Table 3.6 shows the weightage of the positional values of the hexadecimal number:
Table 3.6
Therefore, 5AF.D (16) = 1455.8125(10)
58
Data Representation
Adding a leading 0 as the MSB into the whole number and adding a 0 trailing 0 as the LSB into the
fractional
eÁw binary number does not change the value of the number.
59
Data Representation
Table 3.5 shows each hexadecimal number may be represented as a 4-digit number.
Table 3.5
60
Data Representation
eÁw
61
Data Representation
1 7 5 3 3 6
62
Data Representation
Example 3.21 If in a Computer of word size of 1 byte (8 bits), then an integer +83 and -83 is
eÁw
represented in 8-bit sign-magnitude representation as
27 = 128 numbers can be represented using 7 bits, numbers from 0 to +127 and 0 to -128.
63
Data Representation
Example 3.24
All modern computers operate based on 2’s complement representation because of its hardware
being simpler which makes the computer work faster.
The above table adds only two bits and gives sum and carry. If a carry is generated, it should be
carried over to the addition of next two bits. Thus the addition is a 3-bit addition.
64
Data Representation
Table 3.8 gives the rules to add two addend bits and a carry generated from the addition of previous
bits. eÁw
Addend1 Addend2 Previous carry Sum Carry
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
Table 3.8
Carry 1
Example 3.25 Add 75 and 18 in binary
Carry
75 =Addend1 1
1001011
64 + 8 + 2 + 1 = 1001011
Addend2
Addend1
18 =Carry
16 + 2 = 10010 10010
1001011
1
Addend2
Addend1
Carry 10010
1001011
11
Sum
Carry 1011101
Addend2
Addend1 10010
1001011
Sum 1
Addend 1011101
1001011
Addend2
Sum 2
Addend 10010
1011101
10010
Sum
Sum 1011101
1011101
Table 3.8
When we subtract a 1 from a 0, it is necessary to borrow 1 from the next left column i.e. from the
next higher order position.
65
Data Representation
Simple subtraction
75 = 64 + 8 + 2 +1 = 1001011
25 = 16 + 8 + 1 = 11001
Borrow
Minuend 1001011
Subtrahend 11001
ddd
Difference 110010
Case1: Subtracting a smaller number from a larger number (minuend is greater than subtrahend)
Step 1: Find the 1’s complement of the subtrahend.
Step 2: Add this to the minuend.
Step 3: Carry is generated. This carry is called as the end around carry.
Step 4: Add the end around carry back to the LSB to get the final difference.
Example 3.28 Subtract 15 from 23 using 1’s compliment
Minuend 23 10111
Subtrahend -15 - 01111
? ?
Minuend 10111
1’s compliment of Subtrahend +10000
End around carry 100111
Add end carry to LSB + 1
Difference 1000
66
Data Representation
Case 2: Subtracting a larger number from a smaller number (minuend is less than subtrahend).
Step
eÁw1: Find the 1’s complement of the subtrahend.
Step 2: Add this to the minuend.
Step 3: There will be no carry. Re-complement the answer to get the difference.
Step 4: Add the end around carry back to the LSB to get the final difference.
Minuend 011001
1’s compliment of Subtrahend + 001011
100100
There is no carry. Therefore re-complement and insert a negative sign, we get - 011011
67
Data Representation
Case 2: Subtracting a larger number from a smaller number (minuend is less than subtrahend).
Step 1: Find the 2’s complement subtrahend.
Step 2: Add it to the minuend.
Step 3: There is no carry. Hence take the 2’s complement of the answer and place a negative sign in
front.
0101
0101 0011
0011 0111
0111
68
Data Representation
4-bit BCD code only 24 =16 configurations are possible which is insufficient to represent the
In eÁw
various characters used by computers. Hence 6-bit BCD code was developed by adding two zone
positions with which it is possible to represent 26 = 64 characters.
BCD code BCD code
Character Character
Zone Digit Zone Digit
A 01 0 0 0 1 J 10 0 0 0 1
B 01 0 0 1 0 K 10 0 0 1 0
C 01 0 0 1 1 L 10 0 0 1 1
D 01 0 1 0 0 M 10 0 1 0 0
E 01 0 1 0 1 N 10 0 1 0 1
F 01 0 1 1 0 O 10 0 1 1 0
G 01 0 1 1 1 P 10 0 1 1 1
H 01 1 0 0 0 Q 10 1 0 0 0
I 01 1 0 0 1 R 10 1 0 0 1
Example 3.33: The decimal number 537 would be represented in the XS-3 code as
5 3 7 Decimal digit
0101 0011 0111 8421 BCD Code
0011 0011 0011 Add 3 (0011)
1000 1010 0110 XS-3 Code
69
There are 8 bit BCD systems. They are EBCDIC and ASCII.
iii. EBCDIC code - EBCDIC stands for Extended Binary Coded Decimal Interchange Code
This coding was developed by IBM. It is an 8 bit code and so it has 28 = 256 possible code groups
This coding scheme is used with large computers as mainframes.
teletypes and so the descriptions are somewhat obscure. If someone says they want your CV however in
ASCII format,
eÁw all this means is they want ‘plain’ text with no formatting such as tabs, bold or underscoring
the raw format that any computer can understand. This is usually so they can easily import the file into their
own applications without issues. Notepad.exe creates ASCII text, or in MS Word you can save a file as
‘text only’.
71
Data Representation
Review Questions
72
Data Representation
73
74