Lecture 02
Lecture 02
…25 24 23 22 21 20.
4
Decimal(integer) to Binary Conversions
26 2 5 2 4 2 3 2 2 21 2 0.
64 32 16 8 4 2 1.
0 1 1 0 0 0 1.
5
Decimal fraction to Binary Conversions
MSB
0.188 x 2 = 0.376 carry = 0
0.376 x 2 = 0.752 carry = 0
0.752 x 2 = 1.504 carry = 1
0.504 x 2 = 1.008 carry = 1
0.008 x 2 = 0.016 carry = 0
Answer = .00110 (for five significant digits)
6
Hexadecimal Numbers
Decimal Hexadecimal Binary
0 0 0000
Hexadecimal uses sixteen characters to 1 1 0001
represent numbers: the numbers 0 2 2 0010
through 9 and the alphabetic characters 3 3 0011
A through F. 4 4 0100
5 5 0101
6 6 0110
Large binary number can easily 7 7 0111
be converted to hexadecimal by 8 8 1000
grouping bits 4 at a time and writing 9 9 1001
the equivalent hexadecimal character. 10 A 1010
11 B 1011
Express 1001 0110 0000 11102 in 12 C 1100
hexadecimal: 13 D 1101
Group the binary number by 4-bits 14 E 1110
starting from the right. Thus, 960E 15 F 1111
7
Hexadecimal Numbers
Decimal Hexadecimal Binary
0 0 0000
Hexadecimal is a weighted number
1 1 0001
system. The column weights are 2 2 0010
powers of 16, which increase from 3 3 0011
right to left. 4 4 0100
5 5 0101
6 6 0110
{
163 162 161 160.
Column weights 4096 256 16 1 .
7
8
7
8
0111
1000
9 9 1001
Express 1A2F16 in decimal. 10 A 1010
11 B 1011
Start by writing the column weights:
12 C 1100
4096 256 16 1
13 D 1101
1 A 2 F16
14 E 1110
1(4096) + 10(256) +2(16) +15(1) = 670310 15 F 1111
8
Octal Numbers
Decimal Octal Binary
0 0 0000
Octal uses eight characters the numbers
1 1 0001
0 through 7 to represent numbers. 2 2 0010
There is no 8 or 9 character in octal. 3 3 0011
4 4 0100
5 5 0101
Binary number can easily be
6 6 0110
converted to octal by grouping bits 3 at 7 7 0111
a time and writing the equivalent octal 8 10 1000
character for each group. 9 11 1001
10 12 1010
Express 1 001 011 000 001 1102 in
11 13 1011
octal: 12 14 1100
Group the binary number by 3-bits 13 15 1101
starting from the right. Thus, 1130168 14 16 1110
15 17 1111
9
Octal Numbers
Decimal Octal Binary
10
Binary ↔ Octal ↔ Hex Shortcut
Because binary, octal, and hex number systems are all powers of two
(which is the reason we use them) there is a relationship that we can
exploit to make conversion easier.
1 0 1 1 0 1 0 2 = 132 8 = 5A H
To convert directly between binary and octal, group the binary bits into
sets of 3 (because 23 = 8). You may need to pad with leading zeros.
0 0 1 0 1 1 0 1 0 2= 1 3 28
5 A 0101 1 010
11
Example: Binary ↔ Octal ↔ Hex
Example:
Using the shortcut technique, convert the hexadecimal number A6 16
into its binary and octal equivalent. Use your calculator to check your
answers.
12
Example: Binary ↔ Octal ↔ Hex
Example:
Using the shortcut technique, convert the hexadecimal number A6 16
into its binary & octal equivalent. Use your calculator to check your
answers.
Solution:
First convert the hexadecimal number into binary by expanding the
hexadecimal digits into binary groups of (4).
A 6 16
A616 = 101001102
1010 0110
Convert the binary number into octal by grouping the binary bits into
groups of (3).
010100110
101001102 = 2468
2 4 6
13
Signed Number Representation
• Signed Numbers in Base-2
• Represented (usually) by
• Sign-Magnitude Method
• 1’s Complement Method
• 2’s Complement Method
17
Range of Signed Integers
• Whereas before, the range of an unsigned 4-bit binary number would
have been from 0 to 15, or 0 to F in hexadecimal.
• We now have a reduced range of -7 to +7. Thus an unsigned binary
number does not have a single sign-bit, and therefore can have a
larger binary range as the most significant bit (MSB) is just an extra
bit or digit rather than a used sign bit.
18
Disadvantage of Signed Magnitude Method
• The disadvantage here is that whereas before we had a full
range n-bit unsigned binary number, we now have an n-1
bit signed binary number giving a reduced range of digits
from
• Another disadvantage here of the sign-magnitude form is
that we can have a positive result for zero, +0 or 00002, and a
negative result for zero, -0 or 10002. Both are valid but which
one is correct.
19
Example
Convert the following decimal values into signed binary numbers using
the sign-magnitude format
-1510 as a 6-bit number ⇒ 1011112
20
Signed Numbers
• Sign-Magnitude Method
21
Signed Numbers (cont…/3)
• 1’s Complement Method
22
Signed Numbers (cont…/4)
23
Signed Numbers (cont…/4)
24
Signed Numbers (cont…/4)
25
Signed Numbers (cont…/4)
26
Signed Numbers (cont…/4)
27
Signed Numbers (cont…/4)
28
Signed Numbers (cont…/4)
29
Signed Numbers (cont…/4)
30
Signed Numbers (cont…/5)
The Decimal Value of Signed Number
31
Signed Numbers (cont…/5)
The Decimal Value of Signed Number
32
Signed Numbers (cont…/5)
The Decimal Value of Signed Number
33
Signed Numbers (cont…/5)
The Decimal Value of Signed Number
34
Signed Numbers (cont…/5)
The Decimal Value of Signed Number
35
Signed Numbers (cont…/5)
The Decimal Value of Signed Number
36
Signed Numbers (cont…/6)
The Decimal Value of Signed Number
37
Signed Numbers (cont…/6)
The Decimal Value of Signed Number
38
Signed Numbers (cont…/6)
The Decimal Value of Signed Number
39