iii. Powers of 2
Representation:
Binary Data Representation contd.
Binary Data Representation contd.
Binary Data Representation contd.
Binary Data Representation contd.
Useful Number Systems for Computers
Name Base Digits
dual 2 0, 1
binary
octal 8 0, 1, 2, 3, 4, 5, 6, 7
decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Decimal Number System
Z = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ; B = 10
Each position to the left of a digit increases by a power of 10.
Each position to the right of a digit decreases by a power of 10.
Example:
4769210 = 2 100 +
9 101 +
6 102 +
7 103 +
4 104
= 2 + 90 + 600 + 7000 + 40000
Binary Number System
Z = { 0, 1 } ; B = 2
Each position to the left of a digit increases by a power of 2.
Each position to the right of a digit decreases by a power of 2.
Example:
101110012 = 1 20 +
0 21 +
0 22 +
1 23 +
1 24 +
1 25 +
0 26 +
1 27
= 1 + 8 + 16 + 32 + 128
= 18510
Counting in Binary
Decimal Dual Decimal Dual
0 00 000 16 10 000
1 00 001 17 10 001
2 00 010 18 10 010
3 00 011 19 10 011
4 00 100 20 10 100
5 00 101 21 10 101
6 00 110 22 10 110
7 00 111 23 10 111
8 01 000 24 11 000
9 01 001 25 11 001
10 01 010 26 11 010
11 01 011 27 11 011
12 01 100 28 11 100
13 01 101 29 11 101
14 01 110 30 11 110
15 01 111 31 11 111
Octal Number System
Z = { 0, 1, 2, 3, 4, 5, 6, 7 } ; B = 8
Each position to the left of a digit increases by a power of 8.
Each position to the right of a digit decreases by a power of 8.
Example:
124038 = 3 80 +
0 81 +
4 82 +
2 83 +
1 84
= 3 1 + 0 8 + 4 64 + 2 512 + 1 4096
= 537910
Counting in Octal
Decimal Octal Decimal Octal
0 0 0 16 2 0
1 0 1 17 2 1
2 0 2 18 2 2
3 0 3 19 2 3
4 0 4 20 2 4
5 0 5 21 2 5
6 0 6 22 2 6
7 0 7 23 2 7
8 1 0 24 3 0
9 1 1 25 3 1
10 1 2 26 3 2
11 1 3 27 3 3
12 1 4 28 3 4
13 1 5 29 3 5
14 1 6 30 3 6
15 1 7 31 3 7
Hexadecimal Number System
Z = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F } ; B = 16
Each position to the left of a digit increases by a power of 16. Each
position to the right of a digit decreases by a power of 16.
Example:
FB40A16 = 10 . 160 +
0 . 161 +
4 . 162 +
11 . 163 +
15 . 164
= 10 . 1 + 0 . 16 + 4 . 256 + 11 . 4096 + 15 . 65536
= 1,029,13010
Counting in Hexadecimal
Decimal Hexadecimal Decimal Hexadecimal
0 00 16 10
1 01 17 11
2 02 18 12
3 03 19 13
4 04 20 14
5 05 21 15
6 06 22 16
7 07 23 17
8 08 24 18
9 09 25 19
10 0A 26 1A
11 0B 27 1B
12 0C 28 1C
13 0D 29 1D
14 0E 30 1E
15 0F 31 1F
Comparison of Number Systems
Decimal Dual Octal Hexadecimal Decimal Dual Octal Hexadecimal
0 00 000 00 00 16 10 000 20 10
1 00 001 01 01 17 10 001 21 11
2 00 010 02 02 18 10 010 22 12
3 00 011 03 03 19 10 011 23 13
4 00 100 04 04 20 10 100 24 14
5 00 101 05 05 21 10 101 25 15
6 00 110 06 06 22 10 110 26 16
7 00 111 07 07 23 10 111 27 17
8 01 000 10 08 24 11 000 30 18
9 01 001 11 09 25 11 001 31 19
10 01 010 12 0A 26 11 010 32 1A
11 01 011 13 0B 27 11 011 33 1B
12 01 100 14 0C 28 11 100 34 1C
13 01 101 15 0D 29 11 101 35 1D
14 01 110 16 0E 30 11 110 36 1E
15 01 111 17 0F 31 11 111 37 1F
Powers of 2
N 2N N 2N
0 1 17 131,072
1 2 18 262,144
2 4 19 524,288
3 8 20 1,048,576
4 16 21 2,097,152
5 32 22 4,194,304
6 64 23 8,388,608
7 128 24 16,777,216
8 256 25 33,554,432
9 512 26 67,108,864
10 1,024 27 134,217,728
11 2,048 28 268,435,456
12 4,096 29 536,870,912
13 8,192 30 1,073,741,824
4 16,384 31 2,147,483,648
15 32,768 32 4,294,967,296
16 65,536 33 8,589,934,592
Conversions Between Number Systems
Conversion of Natural Numbers
Step 4: 1 : 8 = 0 Remainder: 1
1F216 = 49810
Conversion of Natural Numbers contd.
Conversions between Numbers 2n and 2m
Conversion 2n => 21
= 5 7 28
n = 4: hexadecimal => dual
Replace 4 binary digits by 1 hexadecimal digit.
Example: 110001111100102 = 11 0001 1111 00102
= 3 1 F 216
Conversion of Natural Numbers contd.
Conversion 2n => 2m
2n => 21 => 2m
Example: octal => hexadecimal
263518 = 2 6 3 5 18
= 2 C E 916
Conversion of Rational Numbers
Note: An exact conversion of rational numbers R10 => RB or RB => R10 is
not always possible.
We want: R10 = RB + , where is a "sufficiently" small number.
Logical OR (x v y)
OR 0 1
0 0 1
1 1 1
Binary Logic contd.
Logical NOT (x, negation)
x x
0 1
1 0
"1-1": 1 - 1 = 1 + (-1) = 0 ?
0 001 001
+ 1 001 - 001
1 0 1 0 (= -210) 000
Problem
2-Complement (B-Complement)
Positive numbers are represented as usual.
Negative numbers are created by
- negating the positive value and
- adding one (this avoids the negative zero)
Examples:
Binary Decimal Two's Complement Decimal
0 1001 9 1 0110 + 1 = 1 0111 -9
0 1101 3 1 0010 + 1 = 1 0011 -3
0 0000 0 1 1111 + 1 = 0 0000 0
0 1111 15 1 0000 + 1 = 1 0001 -15
1 1111 -1 (1 1111 - 1) = 1
(1 1110) = 0 0001
1 0110 -10 0 1010 10
2-Complement (B-Complement) contd.
Number ring for 5-digit 2-complement
2-Complement (B-Complement) contd.
With the 2-complement, subtractions can be performed as simple as
additions:
3.141592653589793238462643383279502884197
6.02 x 1023
Hence, the usual format for a 32-bit real (floating point) number is:
Floating Point Arithmetics
Example: 0.740 . 105 + 0.843 . 103
Addition:
1. Multiply of mantissae
2. Normalize mantissae
3. Adjust exponents
4. Add exponents
0.792 . 0.116 =
0.792 . 10-1
+ 0.792 . 10-2
+ 4.7S2 . 10-3
Floating Point Arithmetics contd.
Floating Point Arithmetics contd.
Limited Precision
Note: Not all values can be represented!
Example:
- mantissa: 2 decimal digits
- exponent: 1 decimaldigit
Samplenumber: 74 102 = 7400
_______________________
1. ASCII: American Standard Code for Information Interchange
2. EBCDIC: Extended Binary Coded Decimal Interchange Code (derived from punch card standards)
Representation of Strings contd.
ASCII Character Encoding
D C D C D C D C D C D C D C D C