Professional Documents
Culture Documents
Number System
Joy Mukherjee
1 / 30
Outline
2 / 30
Outline
3 / 30
Bits & Bytes
1 Bit: a single 0 or 1.
2 1 Byte = Consecutive 8 bits
3 1 KiloByte(KB) = 210 Bytes
4 1 MegaByte(MB) = 210 KB = 220 Bytes
5 1 GigaByte(GB) = 210 MB = 220 KB = 230 Bytes
6 1 TeraByte(TB) = 210 GB = 220 MB = 230 KB = 240 Bytes
4 / 30
Outline
5 / 30
Representation of numbers in memory
Representation Digits
Binary {0, 1}
Octal {0, 1, 2, 3, 4, 5, 6, 7}
Decimal {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Hexadecimal {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}
Table: Number Representation
6 / 30
Non-negative Decimal Non-negative Binary
1 If n is equal to 0, write the remainders in the reverse sequence.
2 Divide n by 2 and remembering the intermediate remainders obtained.
3 Remember the remainder.
4 Goto step 1.
Divide by n Remainder
2 157
2 78 1
2 39 0
2 19 1
2 9 1
2 4 1
2 2 0
2 1 0
2 0 1
(157)10 = (10011101)2
Table: Decimal to Binary
7 / 30
Non-negative Binary Non-negative Decimal
Position 7 6 5 4 3 2 1 0
Binary 1 0 0 1 1 1 0 1
Decimal 27 + 0+ 0+ 24 + 23 + 22 + 0+ 20
(10011101)2 = (157)10
Table: Binary to Decimal
8 / 30
Non-negative Decimal Non-negative Octal
1 If n is equal to 0, write the remainders in the reverse sequence.
2 Divide n by 8 and remembering the intermediate remainders obtained.
3 Remember the remainder.
4 Goto step 1.
Divide by n Remainder
8 157
8 19 5
8 2 3
8 0 2
(157)10 = (235)8
(157)10 = ({10}{011}{101})2 = (235)8
Table: Decimal to Octal
9 / 30
Non-negative Octal Non-negative Decimal
Position 2 1 0
Octal 2 3 5
Decimal 2*82+ 3*81 + 5*80
(235)8 = (157)10
Table: Octal to Decimal
10 / 30
Non-negative Decimal Non-negative Hexadecimal
1 If n is equal to 0, write the remainders in the reverse sequence.
2 Divide n by 16 and remembering the intermediate remainders
obtained.
3 Remember the remainder.
4 Goto step 1.
Divide by n Remainder
16 157
16 9 13(D)
16 0 9
(157)10 = (9D)16
(157)10 = ({1001}{1101})2 = (9D)16
Table: Decimal to Hexadecimal
11 / 30
Non-negative Hexadecimal Non-negative Decimal
Position 1 0
Hexadecimal 9 D
Decimal 9*161+ D*160
(9D)16 = (157)10
Table: Hexadecimal to Decimal
12 / 30
Outline
13 / 30
Representation of Signed Integers
14 / 30
Signed Magnitude Representation
1 0 means positive
2 1 means negative
2 The remaining t-1 bits store the binary representation of |n|.
Example:
1 The 7-bit binary representation of 70 is (1000110)2 .
2 The 8-bit signed magnitude representation of 70 is (01000110)2 .
3 The 8-bit signed magnitude representation of -70 is (11000110)2 .
15 / 30
Signed Magnitude Representation: Notes
16 / 30
1s Complement Representation
18 / 30
2s Complement Representation
19 / 30
2s Complement Representation: Example & Notes
20 / 30
Outline
21 / 30
Summary: 4-bit Representations of Signed Integers
Decimal Signed Magnitude 1s Complement 2s Complement
+7 0111 0111 0111
+6 0110 0110 0110
+5 0101 0101 0101
+4 0100 0100 0100
+3 0011 0011 0011
+2 0010 0010 0010
+1 0001 0001 0001
0000 0000
0 or 0r 0000
1000 1111
-1 1001 1110 1111
-2 1010 1101 1110
-3 1011 1100 1101
-4 1100 1011 1100
-5 1101 1010 1011
-6 1110 1001 1010
-7 1111 1000 1001
-8 No Representation No Representation 1000
23 / 30
IEEE floating point standard
24 / 30
IEEE floating point standard (cont.)
25 / 30
IEEE floating point standard (cont.)
(172.93)10
= (10101100.11101110 . . .)2
= (1.01011001110111000...)2 27
= (0.101011001110111000...)2 28
Decimal fraction 0.93 does not have a terminating binary expansion.
Solution: Approximation of the fractioal part through truncation after
y bits.
If y = 10
(1.0101100111)2 27
= (20 + 22 + 24 + 25 + 28 + 29 + 210 ) 27
= 27 + 25 + 23 + 22 + 21 + 22 + 23
= 128 + 32 + 8 + 4 + 0.5 + 0.25 + 0.125
= 172.875
This example illustrates how to store approximate representations of real
numbers using a fixed amount of bits.
26 / 30
IEEE 754 Floating-point Format
Normal Form: If we write the expansion in the normal form with only
one 1 bit (and nothing else) to the left of the binary point, then it is
sufficient to store only the fractional part (0101100111 in our
example) and the exponent of 2 (7 in the example).
This is is done by the IEEE 754 floating-point format.
This is a 32-bit representation of signed floating point numbers. The
32 bits are used as follows:
31 30 29 ... 24 23 22 21 ... 1 0
S E7 E6 ... E1 E0 M22 M21 ... M1 M0
The normal number that this 32-bit value stores is interpreted as:
(1)S (1.M22 M21 . . . M1 M0 )2 2[(E7 E6 ...E1 E0 )2 127]
Biggest positive real number:
0 11111110 1111111 11111111 11111111
(1.11111111111111111111111) 2127 =
(2 0.000000000000000000000001) 2127 2128 3.403 1038 .
Smallest positive real number:
0 00000001 0000000 00000000 00000000
1.00000000000000000000000 2126 = 2126 1.175x1038 .
28 / 30
Denormal Numbers: IEEE standard
29 / 30
Special Numbers
Recall that the exponent bits were not allowed to take the value 0 or 255.
This value corresponds to some special numbers.
30 / 30