Representation of Data Ma King Man
Reference Text Book: Volume 2 Notes: Chapter 19
Road Map Number System Base Conversion between binary, octal and hexadecimal system Base conversion from any base to decimal Base concersion from decimal to any base Fixed - point representation Floating - point number representation Comparison between fixed - point representation and floating point representation
Lets start
Number System Denary base 0,1,2,3,4,5,6,7,8,9 Binary base 0,1 Octal base 0,1,2,3,4,5,6,7 Hexadecimal base 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Compare… A B C D E F
Base Conversion between binary, octal and hexadecimal system Method 3 binary digits = 1 octal digit 4 binary digits = 1 hexadecimal digit
Example (ii) = (ii) =75 (16)
Example (ii) = (ii) = 165 (8)
Example 3 1A46 (16) = (ii)
Example (8) = (ii)
Base conversion from any base to decimal Method: d n d n-1 d n-2 …… d 1 d 0 d -1 d -2 …… d -m+1 d -m d n b n +d n-1 b n-1 + …… +d 1 b+d 0 +d -1 b -1 + …… +d -m b -m(10)
Examples E.g (ii) =1x x x x x x2 -2 =13.75 E.g (8) =1x x x x x x8 -2 = E.g.311.8(16) =1x x x16 -1 =17.5
Base conversion from decimal to any base ……… ……… ……… ……….1 27 ……….0 23 ……….1 1 Step 1: Convert the integral part: 234 = (ii) Step 2: Convert the fraction part 0.25 = 0.01(ii).25 x x Step 3: Therefore, = (ii)
Lets Try…… E.g = 27.04(8) = 27.04(8)E.g = (ii) = (ii)
Fixed – point representation Usually the point is fixed at the right to the L.S.B. – Least significant bit – i.e. integer. Assume 8 – bit word storage is used (8 – bit per unit) Bit 7 is the sign bit of the number “ 0 ” = positive “ 1 ” = negative
The fixed point representation has the following format: Sign bit
3 methods of fixed-point representation Sign-and-magnitude representation One ’ s complement representation (optional) Two ’ s complement representation
Sign-and-magnitude (i) The leftmost bit indicates the sign. (ii) The remaining bits give the magnitude of the number. E.g (ii) is stored as (+21 in dec.) And (ii) is stored as (-21 in dec.) Range:For 8 – bit word: The smallest number is (-127) The largest number is (+127) Disadvantages: 2 representations for zero: , Requires extra circuit to perform addition and subtraction.
One’s complement representation (i) Add zeros to the left of the binary numbers until the number is fitted the given length. (ii) For a positive integer, the binary pattern is left unchanged. (iii) For a negative integer, 0 is replaced by 1 and 1 by 0. E.g (ii) is stored as And (ii) is stored as Range:For 8 – bit word: The smallest number is (- 127) The largest number is (+127) Disadvantages: Same as sign-and-magnitude representation Zero: ,
Two’s complement representation (Most commonly used) (i) and (ii) are same as 1 ’ s complement method. For a negative integer, add 1 to the rightmost bit of it ’ s 1 ’ s complement. E.g (ii) is stored as And – 10101(ii) is stored as Range: For 8 – bit word: The smallest number is (-128) The largest number is (+127) Advantages: It has wider range than both sign-and-magnitude and 1 ’ s complement, and no ambiguity for zero. Subtraction can be done by addition, no extra circuit is required.
Example 1 Assume 8 – bit word and 2 ’ s complement notation is used. E.g = (binary no.) = (internal representation) = (internal representation) = (binary no.) =
Example 2 E.g.23 – 17 =10111 – 10001(binary no.) = (-10001)(internal representation) = (internal representation) = (internal representation) =110 (ii) (binary no.) =
Example 3 E.g. 17 – 23 =10001 – = (-10111) = = =-110 (ii) =
Special cases (-21) (-75) (-96) (-117) (-83) (+56) (+117) (+44) (-95) Carry discard Overflow Error