Number Systems
Common Number Systems
Used by Used in
System Base Symbols humans? computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa- 16 0, 1, … 9, No No
decimal A, B, … F
Quantities/Counting (1 of 3)
Hexa-
Decimal Binary Octal decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
Quantities/Counting (2 of 3)
Hexa-
Decimal Binary Octal decimal
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
Quantities/Counting (3 of 3)
Hexa-
Decimal Binary Octal decimal
16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
23 10111 27 17
Conversion Among Bases
The possibilities:
Decimal Octal
Binary Hexadecimal
Quick Example
2510 = 110012 = 318 =1916
Base
Binary to Decimal
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
ABC16 => C x 160 = 12 x 1 = 12
B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
Decimal to Binary
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
111 000 101
(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
0001 0000 1010 1111
(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 011 010 111
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
001 000 111 110
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
0001 1111 0000 1100
1 7 4 1 4
(1F0C)16 = (17414)8
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
33
1110101
703
1AF
Don’t use a calculator!
Exercise – Convert …
Answer
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
26 210 = 216 = 65,536
or…
26 210 = 64 210 = 64k
Binary Addition (1 of 2)
Two 1-bit values
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)
-27 = 10011011 (Signed Magnitude)
11100100 (1’s Complement)
11100101 (2’s Complement)
Binary Subtraction
9-7 = ?
9= 00001001
7= 00000111
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:
If there is any end carry, add it and sum obtained is the
answer.
If there is no carry, answer is
–(flip the bits of the sum obtained).
Binary Subtraction (1’s Complement)
9-7 = ?
9= 00001001
7= 00000111
I’s complement of 7 = 11111000
9 – 7 = 9+(-7)
00001001 (1’s complement representation of 9)
+11111000 (1’s complement representation of -7)
__________
1 00000001
__________
Adding carry 1 to 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
__________
No Carry, result is a negative number, therefore
Ans = -(flip the bits of 11111101) = - (00000010)
Binary Subtraction (2’s Complement)
There are two possible cases while
performing subtraction using 2’s complement:
If there is any end carry, just ignore it and sum obtained
is the answer.
If there is no carry, answer is –(flip the bits of the sum
obtained plus one).
Binary Subtraction (2’s Complement)
9-7 = ?
9= 00001001
7= 00000111
2’s complement representation of -7 = 11111001
9 – 7 = 9+(-7)
00001001 (2’s complement representation of 9)
+11111001 (2’s complement representation of -7)
__________
100000010
__________
If end carry is there ignore it.
Binary Subtraction
(2’s Complement)
7-9 = ?
9= 00001001, 7= 00000111, 2’s complement of 9 = 11110111
7-9 = 7+(-9)
00000111 (2’s complement representation of 7)
+11110111 (2’s complement representation of -9)
__________
11111110
__________
No Carry, therefore
ANS = - (flip the bits of 11111110 plus 1)
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±𝑒
Where ± : is the sign plus or minus
M : is the mantissa or significant
e : is the exponent
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 1: (345)6 = ( ? )10
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 1: (345.15)6 = ( ? )10
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
____________
( 137.31 )10 = ( ? )3 .31
3 137 x 3
3 45 2 0 .93
3 15 0 x 3
3 5 0 2 .79
3 1 2 x 3
3 0 1 2 .37
x 3
=(12002.0221…..)3 1 .11
etc.