representation of data
DESCRIPTION
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 - PowerPoint PPT PresentationTRANSCRIPT
Representation of DataRepresentation of Data
Ma King ManMa King Man
ReferenceReference
Text Book: Volume 2Text Book: Volume 2
Notes: Chapter 19Notes: Chapter 19
Road MapRoad MapNumber SystemNumber SystemBase Conversion between binary, octal and heBase Conversion between binary, octal and hexadecimal systemxadecimal systemBase conversion from any base to decimalBase conversion from any base to decimalBase concersion from decimal to any base Base concersion from decimal to any base Fixed - point representationFixed - point representationFloating - point number representationFloating - point number representationComparison between fixed - point representatComparison between fixed - point representation and floating point representationion and floating point representation
Lets startLets start
Number SystemNumber System
Denary baseDenary base0,1,2,3,4,5,6,7,8,90,1,2,3,4,5,6,7,8,9
Binary baseBinary base0,10,1
Octal baseOctal base0,1,2,3,4,5,6,70,1,2,3,4,5,6,7
Hexadecimal baseHexadecimal base0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Compare…Compare…0 000 0 0
1 001 1 1
2 010 2 2
3 011 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Base Conversion between Base Conversion between binarybinary, , octaloctal and and hexadecimalhexadecimal
systemsystem
MethodMethod
3 3 binarybinary digits = 1 digits = 1 octal digitoctal digit
4 4 binarybinary digits = 1 digits = 1 hexadecimal digithexadecimal digit
Example 1Example 1
11101011110101(ii)(ii)
=111 0101=111 0101(ii)(ii)
=75=75(16)(16)
Example 2Example 2
11101011110101(ii)(ii)
= 1 110 101= 1 110 101(ii)(ii)
= 165= 165(8)(8)
Example 3Example 3
1A461A46(16)(16)
= 1 1010 0100 0110= 1 1010 0100 0110(ii)(ii)
Example 4Example 4
732732(8)(8)
= 111 011 010= 111 011 010(ii)(ii)
Base conversion from Base conversion from any baseany base to to decimaldecimal
Method:Method:ddnnddn-1n-1ddn-2n-2……d……d11dd00dd-1-1dd-2-2……d……d-m+1-m+1dd-m-m
ddnnbbnn+d+dn-1n-1bbn-1n-1+……+d+……+d11b+db+d00+d+d-1-1bb-1-1
+……+d+……+d-m-mbb-m(10)-m(10)
ExamplesExamplesE.g.1E.g.11101.11(ii)1101.11(ii)== 1x21x233 + 1x2 + 1x222 + 0x2 + 0x211 + 1x2 + 1x200 + 1x2 + 1x2-1-1 + 1x2 + 1x2-2-2
== 13.7513.75E.g.2E.g.2
1234.56(8)1234.56(8)== 1x81x833 + 2x8 + 2x822 + 3x8 + 3x811 + 4x8 + 4x800 + 5x8 + 5x8-1-1 + 6x8 + 6x8-2-2
== 668.71875668.71875E.g.3E.g.3
11.8(16)11.8(16)== 1x161x1611 + 1x16 + 1x1600 + 8x16 + 8x16-1-1
== 17.517.5
Base conversion from Base conversion from decimaldecimal to to any baseany base
2 234
2 117 ……….0
2 58 ……….1
2 29 ……….0
2 14 ……….1
2 7 ……….0
2 3 ……….1
1 ……….1
Step 1: Convert the integral part:234 = 11101010(ii)
Step 2: Convert the fraction part0.25 = 0.01(ii) . 2 5
x 2
0 . 5 0
x 2
1 . 0 0Step 3: Therefore, 234.25 = 11101010.01(ii)
Lets Try……Lets Try……
E.g.2E.g.2
23.062523.0625
= 27.04(8)= 27.04(8)
E.g.3E.g.3
13.12513.125
= 1101.001(ii)= 1101.001(ii)
Fixed – point representationFixed – point representation
Usually the point is fixed at the right Usually the point is fixed at the right to the L.S.B. – Least significant bit – to the L.S.B. – Least significant bit – i.e. integer.i.e. integer.
Assume Assume 8 – bit word8 – bit word storage is used storage is used (8 – bit per unit)(8 – bit per unit)
Bit Bit 77 is the sign bit of the number is the sign bit of the number
““0” = positive0” = positive
““1” = negative1” = negative
The fixed point representation has The fixed point representation has the following format:the following format:
7 6 5 4 3 2 1 0
Sign bit
3 methods of fixed-point 3 methods of fixed-point representationrepresentation
Sign-and-magnitude representationOne’s complement representation (optional)Two’s complement representation
Sign-and-magnitude Sign-and-magnitude (i) The leftmost bit indicates the sign.(i) The leftmost bit indicates the sign.(ii) The remaining bits give the magnitude of the number.(ii) The remaining bits give the magnitude of the number.E.g. +10101(ii) is stored as 00010101 (+21 in dec.)And - 10101(ii) is stored as 10010101 (-21 in dec.)Range: For 8 – bit word:
The smallest number is 11111111 (-127)The largest number is 011111111 (+127)
Disadvantages:2 representations for zero: 00000000, 10000000Requires extra circuit to perform addition and subtraction.
One’s complement representationOne’s complement representation(i) Add zeros to the left of the binary numbers until the (i) Add zeros to the left of the binary numbers until the number is fitted the given length.number is fitted the given length.(ii) For a positive integer, the binary pattern is left (ii) For a positive integer, the binary pattern is left unchanged.unchanged.(iii) For a negative integer, 0 is replaced by 1 and 1 by 0(iii) For a negative integer, 0 is replaced by 1 and 1 by 0..E.g.E.g. +10101(ii) is stored as 00010101+10101(ii) is stored as 00010101AndAnd - 10101(ii) is stored as 11101010- 10101(ii) is stored as 11101010Range:Range:For 8 – bit word:For 8 – bit word:
The smallest number is 10000000 (- 127)The smallest number is 10000000 (- 127)The largest number is 01111111 (+127)The largest number is 01111111 (+127)
Disadvantages:Disadvantages:Same as sign-and-magnitude representationSame as sign-and-magnitude representationZero: 00000000, 11111111Zero: 00000000, 11111111
Two’s complement representation Two’s complement representation (Most commonly used)(Most commonly used)
(i) and (ii) are same as 1’s complement method.(i) and (ii) are same as 1’s complement method.For a negative integer, add 1 to the rightmost bit of it’s For a negative integer, add 1 to the rightmost bit of it’s 1’s complement.1’s complement.E.g.E.g. +10101(ii) is stored as 00010101+10101(ii) is stored as 00010101And –10101(ii) is stored as 11101011And –10101(ii) is stored as 11101011Range:Range: For 8 – bit word:For 8 – bit word:
The smallest number is 10000000 (-128)The smallest number is 10000000 (-128)The largest number is 01111111 (+127)The largest number is 01111111 (+127)
Advantages:Advantages:It has wider range than both sign-and-magnitude and 1’s It has wider range than both sign-and-magnitude and 1’s complement, and complement, and no ambiguity for zerono ambiguity for zero..Subtraction can be done by additionSubtraction can be done by addition, no extra circuit is , no extra circuit is required.required.
Example 1Example 1Assume 8 – bit word and 2’s complement notation is used.E.g. 23 + 17= 10111 + 10001 (binary no.)= 00010111 + 00010001 (internal representation)= 00101000 (internal representation)= + 101000 (binary no.)= 40
0 0 0 1 0 1 1 1
+ 0 0 0 1 0 0 0 1
0 0 1 0 1 0 0 0
Example 2Example 2E.g. 23 – 17
= 10111 – 10001 (binary no.)= 10111 + (-10001) (internal representation)= 00010111 + 11101111 (internal representation)= 00000110 (internal representation)= 110(ii) (binary no.)
= + 6
0 0 0 1 0 1 1 1
+ 1 1 1 0 1 1 1 1
0 0 0 0 0 1 1 0
Example 3Example 3E.g. 17 – 23
= 10001 – 10111= 10001 + (-10111)= 00010001 + 11101001= 11111010= -110(ii)
= -6
0 0 0 1 0 0 0 1
+ 1 1 1 0 1 0 0 1
1 1 1 1 1 0 1 0
Special casesSpecial cases
1 1 1 0 1 0 1 1 (-21)
+ 1 0 1 1 0 1 0 1 (-75)
1 1 0 1 0 0 0 0 0 (-96)
1 0 0 0 1 0 1 1 (-117)
+ 1 0 1 0 1 1 0 1 (-83)
1 0 0 1 1 1 0 0 0 (+56)
0 1 1 1 0 1 0 1 (+117)
+ 0 0 1 0 1 1 0 0 (+44)
1 1 0 1 0 0 0 0 1 (-95)
Carry discard
Overflow Error
Overflow Error