Unit II
Unit II
Four
Data Representation in
Computers
We enter data into a computer or
review (see) output data from a
computer using the letter of
alphabet, various special symbols,
and the numerals in the decimal
number system. But since
computer is an electronic device,
which understands electrical flow
(signal), there is no letter,
symbol or number inside the
computer. Computer works with
binary numbers.
Unit II : Information Representation Page 1
Four
Data Representation in
Computers
We enter data into a computer or
review (see) output data from a
computer using the letter of
alphabet, various special symbols,
and the numerals in the decimal
number system. But since
computer is an electronic device,
which understands electrical flow
(signal), there is no letter,
symbol or number inside the
computer. Computer works with
binary numbers.
Unit II : Information Representation Page 2
Four
Data Representation in
Computers
We enter data into a computer or
review (see) output data from a
computer using the letter of
alphabet, various special symbols,
and the numerals in the decimal
number system. But since
computer is an electronic device,
which understands electrical flow
(signal), there is no letter,
symbol or number inside the
computer. Computer works with
binary numbers.
Unit II : Information Representation Page 3
Four
Data Representation in
Computers
We enter data into a computer or
review (see) output data from a
computer using the letter of
alphabet, various special symbols,
and the numerals in the decimal
number system. But since
computer is an electronic device,
which understands electrical flow
(signal), there is no letter,
symbol or number inside the
computer. Computer works with
binary numbers.
Data Representation
Hexadecimal number system is another number system that works exactly like the decimal and
binary number systems, except that the base is 16. It uses 16 symbols (0-9, and A-F characters
to represent 10-15).
It is important to note that every decimal number system has its equivalent binary number.
For example:
M x 2e = +( .1001110)2 x 2+4
A floating point number is said to be Normalized if the most significant digit of the mantissa is nonzero.
Example: The 8 bit binary number 00011010 is not normalized because of the three 0’s.
The number can be normalized by shifting three positions to the left and discarding the leading 0’s obtains 11010000. The three
shifts multiply the number by 23 = 8. To keep the same value for the floating-point number, the exponent must be subtracted by 3.
Normalized numbers provide the maximum possible precision for the floating point number.
Many computers and all electronic calculators have the built-in capability of performing floating-point arithmetic operations.
Although there is only one way to represent +14, there are three different ways to represent -14 with eight bits.
Sign bit
In signed magnitude representation 1 0001110
In signed 1’s complement representation 1 1110001
In signed 2’s complement representation 1 1110010
The signed magnitude representation of -14 is obtained from +14 by complementing only the sign bit.
The signed 1’s complement representation of -14 is obtained by complementing all the bits of +14, including the sign bit.
The signed 2’s complement representation is obtained by taking the 2’s complement of the positive number, including its sign bit .
Arithmetic Addition:
The addition of two numbers in the signed-magnitude system follows the rules of ordinary arithmetic. If the signs are same, we
add the two magnitudes and give the sum the common sign. If the sign are different, we subtract the smaller magnitude from the
larger and give the result the sign of the larger magnitude.
Add the two numbers, including their sign bits, and discard any carry out of the sign bit position. Numerical examples for
addition are shown below. Note that negative numbers must initially be in 2’s complement and that if the sum obtained after the
addition is negative, it is in 2’s complement form.
+6 00000110 -6 11111010
+13 00001101 +13 00001101
+19 00010011 +7 00000111
In each of the four cases, the operation performed is always addition, including the sign bits. Any carry out of the sign bit position
is discarded, and negative results are automatically in 2’s complement form.
It is worth noting that binary numbers in the signed 2’s complement system are added and subtracted by the same basic addition
and subtraction rules as unsigned numbers.
Therefore, computers need only one common hardware circuit to handle both types of arithmetic.
Overflow:
When two numbers of n digits each are added and the sum occupies n+1 digits, we say that an overflow occurred.
An overflow is a problem in digital computers because the width of registers is finite.
A result that contains n+1 bits cannot be accommodated in a register with a standard length of n bits. For this reason,
many computers detect the occurrence of an overflow, and when it occurs, a corresponding flip-flop is set which can then be
checked by the user.
An overflow may occur if the two numbers added are both positive or both negative.
Example: Two signed binary numbers, +70 and +80, are stored in two 8bit registers.
carries : 0 1 carries: 1 0
+70 0 1000110 -70 1 0111010
+80 0 1010000 -80 1 0110000
+150 1 0010110 -150 0 1101010
Note that the 8 bit result that should have been positive has a negative sign bit and the 8bit result that should have been negative
has a positive sign bit. If, however, the carry out of the sign bit position is taken as the sign bit of the result, the 9 bit answer so
obtained will be correct.
Since the answer cannot be accommodated within 8 bits, we say that an overflow occurred. If the two carries are applied to an
exclusive-OR gate, an overflow will be detected when the output of the gate is equal to 1.
Alpha numeric Code: ASCII (American standard code for information interchange)
It is the standardized alphanumeric code and most widely used by several computer manufacturers as their computer’s internal
code. It is a 7 bit alphanumeric code which has 2 7 =128 different characters to encode 85 characters. ( 52 lowercse and uppercase
alphabets, 10 numerals and 23 punctuation and others symbols as marked on keyboards printers,video display etc.,)
ASCII code can be classified into 2 types as specified below.
(i) ASCII -7 : 7 bit code, which represents 27 =128 different characters. In 7 bits, the first 3 bit represent zone bit and
next 4 bit represent digit.
(ii) ASCII-8 : 8 bit code, which represent 28 = 256 different characters. In 8 bits, the first 4 bit represent zone bit and
next 4 bit represent digit.
ASCII 7 code for characters
LSB MSB b6b5b4
b3b2b1b0 010 011 100 101 110 111
0000 SPACE 0 @ P - P
0001 ! 1 A Q A Q
0010 “ 2 B R B R
0011 # 3 C S C S
0100 $ 4 D T D T
0101 % 5 E U E U
0110 & 6 F V F V
0111 ‘ 7 G W G W
1000 ( 8 H X H X
1001 ) 9 I Y I Y
1010 * : J Z J Z
1011 + ; K [ K {
1100 ‘ < L \ L |
1101 - = M ] M }
1110 . > N ^ N ~
For instance, the letter ‘A’ has the bits b6b5b4 of 100 and the bits b3b2b1b0 of 0001. Therefore, A is represented in ASCII code as
100 0001 41 (hexadecimal)
Character ASCII -7 Code Hexadecimal Equivalent
Zone Digit
0 011 0000 30
1 011 0001 31
2 011 0010 32
… … …. ..
A 100 0001 41
B 100 0010 42
C 100 0011 43
… … … …
A 0100 0001 A1
B 0100 0010 A2
C 0100 0011 A3
… … … …
Ie., 100111
MSB LSB
In the binary to decimal conversion, 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. The binary number system have a base 2, the position
weights are used on the power of 2.
Ex: 100111 = ?
1 x 25 + 0x 24 + 0x 23 + 1x22 + 1x21 + 1x20
1 x 32 + 0x 16 + 0x 8 + 1x4 + 1x2 + 1x1 = 39
100111 = 39 Ans.
Ex- 2: 0.1010 = ?
1 x 2-1 + 0x 2-2 + 1x 2-3 + 0x2-4
1x(1/2) + 0x(1/4) + 1x (1/8) + 0 x (1/16)
1x0.5 + 0x0.25 + 1x 0.125 + 0 x 0.0625
0.1010 = 0.625 Ans.
Conversion from binary to its equivalent decimal and from decimal to its equivalent binary is possible. The method, which is used
for the conversion of decimal into binary, is often called asthe remainder method. This method involves the following steps.
- Begin by dividing the decimal number by 2 (the base of binary number system)
- Note the remainder separately as the rightmost digit of the binary equivalent
- Continually repeat the process of dividing by 2 until quotient is zero and keep writing the remainders after each step of
division (these remainders will either be 0 or 1)- Finally, when no more division can occur, write down the remainders in reverse
Ex: 15 = ?
2 15
2 7 - 1
2 3 - 1
1 - 1
15 = 1111 Ans
Ex 2: 0.625 = ?
0.625 x 2 = 1.25 0.25 with a carry of 1 (MSB)
0.25 x 2 = 0.50 0.50 with a carry of 0
0.50 x 2 = 1.00 0.00 with a carry of 1 (LSB)
0.625 = 0.101
Ex 2: 0.39 = ?
0.39 x 2 = 0.78 0.78 with a carry of 0
0.78 x 2 = 1.56 0.56 with a carry of 1
0.56 x 2 = 1.12 0.12 with a carry of 1
0.39 = 0.011
Note: in this example it is seen that the fraction has not become zero, and that will continue further. For such a case an
approximation is made. For this example, we may take the result up to 3 binary bits after the binary point.
Ex: 3977 = ?
8 3977
8 497 -1
8 62 - 1
7 - 6
Ex: 39 = ?
16 39
2 - 7
39 = 27 Ans
Ex: 256 = ?
16 256
16 16 - 0
1 - 0
Ex: 1723.256 = ?
16 1723
16 107 -11
6 - 11
Ex: 3A.2F = ?
3x 161 + Ax 160 . 2 X 16-1 + 15 X 16-2
Unit II : Information Representation Page 14
=48+10 . (2/10) + ( 15 / 162)
= 58.1836
Conversion from Binary to Hexadecimal :
Ex: 11100101110111
=0011 1001 0111 0111
=3 9 7 7
=3977
Ex: 110101001.0010110
=0001 1010 1001 . 0010 1100
=1 A 9 . 2 C
1
Add (1) + (2) 1 + 0 = 1
Add (2) + (3) 0 +1 = 1
Add (3) + (4) 1 + 0 = 1 then result is 1111 gray code
Gray Code to binary:
Ex: 1111 = ?
(1) (2) (3) (4)
1 1 1 1
1 (5)
Add (5) + (2) 1 +1 =0 (6) note: discard carry 1
Add (6) + (3) 0 +1 = 1 (7)
Add (7) + (4) 1 +1 = 0 note: discard carry 1
then result is 1010 Binary code