3.Number System
3.Number System
Decimal Octal
Binary Hexadecimal
Quick Example
Decimal Octal
Binary Hexadecimal
Binary to Decimal
Technique
◦ Multiply each bit by 2n, where n is the “weight” of
the bit
◦ The weight is the position of the bit, starting from
0 on the right
◦ Add the results
Example
Bit “0”
1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
Octal to Decimal
Decimal Octal
Binary Hexadecimal
Octal to Decimal
Technique
◦ Multiply each bit by 8n, where n is the
“weight” of the bit
◦ The weight is the position of the bit, starting
from 0 on the right
◦ Add the results
Example
7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
Hexadecimal to Decimal
Decimal Octal
Binary Hexadecimal
Hexadecimal to Decimal
Technique
◦ Multiply each bit by 16n, where n is the
“weight” of the bit
◦ The weight is the position of the bit, starting
from 0 on the right
◦ Add the results
Example
Decimal Octal
Binary Hexadecimal
Decimal to Binary
Technique
◦ Divide by two, keep track of the remainder
◦ First remainder bit is LSB (least-significant bit)
◦ Last remainder bit is MSB (most significant
bit)
Example
2 125
(125)10 = (?)2
2 62 1
2 31 0
15 1
2
7 1
2
2 3 1
2 1 1
0 1
(125)10 = (1111101)2
Octal to Binary
Decimal Octal
Binary Hexadecimal
Octal to Binary
Technique
◦ Convert each octal digit to a 3-bit equivalent
binary representation
Example
(705)8 = (?)2
7 0 5
(705)8 = (111000101)2
Hexadecimal to Binary
Decimal Octal
Binary Hexadecimal
Hexadecimal to Binary
Technique
◦ Convert each hexadecimal digit to a 4-bit
equivalent binary representation
Example
(10AF)16 = (?)2
1 0 A F
(10AF)16 = (0001000010101111)2
Decimal to Octal
Decimal Octal
Binary Hexadecimal
Decimal to Octal
Technique
◦ Divide by 8
◦ Keep track of the remainder
Example
(1234)10 = (?)8
8 1234
154 2
8
19 2
8
2 3
8
0 2
(1234)10 = (2322)8
Decimal to Hexadecimal
Decimal Octal
Binary Hexadecimal
Decimal to Hexadecimal
Technique
◦ Divide by 16
◦ Keep track of the remainder
Example
(1234)10 = (?)16
16 1234
16 77 2
16 4 13 = D
0 4
(1234)10 = (4D2)16
Binary to Octal
Decimal Octal
Binary Hexadecimal
Binary to Octal
Technique
◦ Group bits in threes, starting on right
◦ Convert to octal digits
Example
(1011010111)2 = (?)8
1 3 2 7
(1011010111)2 = (1327)8
Binary to Hexadecimal
Decimal Octal
Binary Hexadecimal
Binary to Hexadecimal
Technique
◦ Group bits in fours, starting on right
◦ Convert to hexadecimal digits
Example
(1010111011)2 = (?)16
10 1011 1011
2 B B
(1010111011)2 = (2BB)16
Octal to Hexadecimal
Decimal Octal
Binary Hexadecimal
Octal to Hexadecimal
Technique
◦ Use binary as an intermediary
Example
(1076)8 = (?)16
1 0 7 6
2 3 E
(1076)8 = (23E)16
Hexadecimal to Octal
Decimal Octal
Binary Hexadecimal
Hexadecimal to Octal
Technique
◦ Use binary as an intermediary
Example
(1F0C)16 = (?)8
1 F 0 C
1 7 4 1 4
(1F0C)16 = (17414)8
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
33
1110101
703
1AF
Hexa-
Decimal Binary Octal decimal
33 100001 41 21
117 1110101 165 75
451 111000011 703 1C3
431 110101111 657 1AF
Review – multiplying powers
For common bases, add powers
ab ac = ab+c
A B A+B
0 0 0
0 1 1
1 0 1
1 1 10
“two”
Binary Addition (2 of 2)
Two n-bit values
◦ Add individual bits
◦ Propagate carries
◦ E.g.,
1 1
10101 21
+ 11001 + 25
101110 46
Binary Representation
Signed Magnitude Representation
+9 =00001001 -9 = 10001001
1’s Complement Representation
+9 = 00001001 -9= 11110110
2’s Complement Representation
+9 = 00001001 -9 = 11110111
Binary Representation
Express the following in signed magnitude,
1’s Complement and 2’s Complement
form:
35
-27
Binary Representation
35 = 00100011 (Signed Magnitude)
00100011 (1’s Complement)
00100011 (2’s Complement)
9–7= ?
00001001 (Signed magnitude representation of 9)
- 00000111 (Signed magnitude representation of -7)
__________
00000010 (Correct Answer)
__________
7–9=?
00000111 (Signed magnitude representation of 7)
- 00001001 (Signed magnitude representation of -9)
________
? ? ? ? ?110 (operation (0-1) not possible, Can’t find Answer)
_________
Binary Subtraction
(Signed Magnitude Representation)
9-7 = ?
9= 00001001
7= 00000111
9 – 7 = 9 + (-7) = ?
00001001 (Signed magnitude representation of 9)
+10000111 (Signed magnitude representation of -7)
__________
100010000 (Wrong Answer)
__________
7 – 9 = 7 + (-9) = ?
00000111 (Signed magnitude representation of 7)
+ 10001001 (Signed magnitude representation of -9)
________
10010000 (Wrong Answer)
_________
Binary Subtraction (1’s Complement)
There are two possible cases while
performing subtraction using 1’s
complement:
9 – 7 = 9+(-7)
00001001 (1’s complement representation of 9)
+11111000 (1’s complement representation of -7)
__________
1 00000001
__________
00000001
+ 1
_________________
00000010 (Binary 2)
_________________
Binary Subtraction (1’s Complement)
7-9 = ?
9= 00001001
7=00000111
I’s complement representation of -9 = 11110110
7-9 = 7+(-9)
00000111 (1’s complement representation of 7)
+11110110 (1’s complement representation of -9)
__________
11111101
__________
9 – 7 = 9+(-7)
00001001 (2’s complement representation of 9)
+11111001 (2’s complement representation of -7)
__________
100000010
__________
No Carry, therefore
00000001
+ 1
__________________
00000010
___________________
Therefore,
ANS = -(00000010)
Multiplication (1 of 3)
Decimal
35
x 105
175
000
35
3675
Multiplication (2 of 3)
Binary, two 1-bit values
A B AB
0 0 0
0 1 0
1 0 0
1 1 1
Multiplication (3 of 3)
Binary, two n-bit values
◦ As with decimal values
◦
1110
x 1011
1110
1110
0000
1110
10011010
Fractions
Decimal to decimal
3.14 =>
4 x 10-2 = 0.04
1 x 10-1 = 0.1
3 x 100 = 3
3.14
Fractions
Binary to decimal
10.1011 =>
1 x 2-4 = 0.0625
1 x 2-3 = 0.125
0 x 2-2 = 0.0
1 x 2-1 = 0.5
0 x 20 = 0.0
1 x 21 = 2.0
2.6875
Fractions
Decimal to binary .14579
x 2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001...
etc.
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
29.8
101.1101
3.07
C.82
Don’t use a calculator!
Exercise – Convert …
Answer
Hexa-
Decimal Binary Octal decimal
29.8 11101.110011… 35.63… 1D.CC…
5.8125 101.1101 5.64 5.D
3.109375 11.000111 3.07 3.1C
12.5078125 1100.10000010 14.404 C.82
Storing Floating Point Numbers
Representation of floating point binary number:
± 𝑀 ∗ 2±𝑒
e.g.
1101.101 can be represented as:
1101101 * 2−3
11011.01* 2−1
1.101101* 23
.1101101* 𝟐𝟒 (Normalization – non zero at MSB)
.01101101* 25
Storing Floating Point Numbers
Total bits = 16 bits
Use 10 bits for mantissa, 6 bits for exponent
.1101101* 𝟐𝟒
M e
Sign bit Sign bit
0 1 1 0 1 1 0 1 0 0 0 0 0 1 0 0
M e
M = Mantissa
e = Exponent
Any base to any base
(345)6 = ( ? )3
Step 2: ( ? )10 = ( ? )3
Any base to any base
(345)6 => 5 x 60 = 5
4 x 61 = 24
3 x 62 = 108
________
13710
____________
( 137 )10 = ( ? )3
3 137
3 45 2
3 15 0
3 5 0
3 1 2
3 0 1
=(12002)3
Any base to any base
(345.15)6 = ( ? )3
Step 2: ( ? )10 = ( ? )3
Any base to any base
(345.15)6 => 5 x 6-2 = 0.14
1 x 6-1= 0.17
5 x 60 = 5
4 x 61 = 24
3 x 62 = 108
________
137.3110
____________