You are on page 1of 38

Digital Logic & Design

Lecture 03
Recap

• Number System Conversion


– Sum-of-Weights for converting to decimal
– Repeated division for converting from decimal

• Binary Arithmetic
– Similar to Decimal Arithmetic
– Multiplying by a constant by shifting left
– Dividing by a constant by shifting right
Signed and Unsigned Numbers

• Unsigned Binary Numbers


• Signed Binary Numbers
– Most significant bit represents sign
– 0 represents a positive number
– 1 represents a negative number
1’s Complement form

• The 1’s complement of a binary number is found by


changing all 1’s to 0’s and all 0’s to 1’s

Binary number 01101

1’s complement 10010


2’s Complement form
• The 2’s complement of a binary number is found by
adding 1 to LSB of 1’s complement.

2’s complement = (1’s complement) + 1

Binary number 01101 (13)


1’s complement 10010
+ 1
2’s complement 10011 (-13)
2’s Complement form
• Alternative method

1. Start at the right with the LSB and write the bits as they are up to and
including the first 1
2. Take the 1’s complement of the remaining bits
2’s Complement form

• 1’s complement form


• 2’s complement form

Binary number 01101(13)


1’s complement 10010
+ 1
2’s complement 10011(-13)
Addition and Subtraction with 2’s
Complement

0101 +5 0101 +5
0010 +2 1110 -2
0111 +7 10011 +3

1011 -5 1011 -5
1110 -2 0010 +2
11001 -7 1101 -3
Addition and Subtraction
2’s complement vs. Signed
2’s Complement Signed Binary
0101 +5 0101 +5
0010 +2 0010 +2
0111 +7 0111 +7

1011 -5 1101 -5
1110 -2 1010 -2
11001 -7 10111 -7
Addition and Subtraction
2’complement vs. Signed

0101 +5 0101 +5
1110 -2 1010 -2
10011 +3 1111 +3

1011 -5 1101 -5
0010 +2 0010 +2
1101 -3 1111 -3
Range of Numbers

• Unsigned
– Positive Numbers Only (0 to 7)
– 3-bit
• Signed Magnitude
– Positive & Negative Numbers (-7 to 7)
– 4-bit
• 2’s Complement
– Positive & Negative Numbers (-8 to 7)
– 4-bit
Range of Numbers
Range & Overflow

• 2 + 7 using 3-bit unsigned binary?


• 9 overflow?
• 2 – 7?
• Can not represent -7 in unsigned binary
Range and Overflow

1011 -5
1101 -3
11000 -8

1011 -5 0101 +5
1100 -4 0100 +4
10111 -9 1001 +9
Range of Binary Numbers

• Processors can handle 64-bit unsigned binary values.


• Maximum unsigned decimal number is 1.8446 x 1019
• How to represent larger numbers?
• How to represent very small numbers?
• How to represent numbers with integer part and
fraction part?
Hexadecimal Number System

• Base 16
• 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
• Representing Binary in compact form
– 11011000001102 = 1B06 H
Counting in Hexadecimal
Decimal Binary Hexadecimal Decimal Binary Hexadecimal

0 0000 0 8 1000 8
1 0001 1 9 1001 9
2 0010 2 10 1010 A
3 0011 3 11 1011 B
4 0100 4 12 1100 C
5 0101 5 13 1101 D
6 0110 6 14 1110 E
7 0111 7 15 1111 F
Counting in Hexadecimal

Decimal Hexa- Decimal Hexa- Decimal Hexa-


Decimal Decimal Decimal
16 10 24 18 32 20
17 11 25 19 33 21
18 12 26 1A 34 22
19 13 27 1B 35 23
20 14 28 1C 36 24
21 15 29 1D 37 25
22 16 30 1E 38 26
23 17 31 1F 39 27
Binary to Hexadecimal Conversion

– (11010110101110010110) 2 = ( ? )16

– 1101 0110 1011 1001 0110

– D 6 B 9 6

– (11010110101110010110) 2 = (D6B96)16
Hexadecimal to Binary Conversion

– (FD13) 16 = ( ? )2

– F D 1 3

– 1111 1101 0001 0011

– (FD13) 16 = (1111 1101 0001 0011 )2


Decimal-Hexadecimal Conversion

• Decimal to Hexadecimal Conversion


• Indirect Method
– Decimal →Binary → Hexadecimal
• Repeated Division by 16
Decimal-Hexadecimal Conversion

• Hexadecimal to Decimal Conversion


• Indirect Method
– Hexadecimal →Binary → Decimal
• Sum-of-Weights
Hexadecimal Addition & Subtraction

• Hexadecimal Addition
– Carry generated
• Hexadecimal Subtraction
– Borrow weight 16
Decimal to Hexadecimal Conversion

Repeated Division by 16
Number Quotient Remainder

2096 131 0

131 8 3

8 0 8
Hexadecimal to Decimal Conversion
Sum-of-Weights

CA02
(C x 163) + (A x 162) + (0 x 161) + (2 x 160)
(12 x 163) + (10 x 162) + (0 x 161) + (2 x 160)
(12 x 4096) + (10 x 256) + (0 x 16) + (2 x 1)
49152 + 2560 + 0 + 2
51714
Hexadecimal Addition

Carry 1
2AC6 6+5=11d Bh
+ 92B5 C+B=23d 17h
BD7B A+2+1=13d Dh
2+9=11d Bh
Hexadecimal Subtraction

Borrow 1,A,21
111
92B5 21-6=15d Fh
- 2AC6 26-C=14d Eh
67EF 17-A=7d 7h
8-2=6d 6h
Octal Number System

• Base 8
• 0, 1, 2, 3, 4, 5, 6, 7
• Representing Binary in compact form
– 11011000001102 = 154068
Counting in Octal

Decimal Binary Octal


0 000 0
1 001 1
2 010 2
3 011 3
4 100 4
5 101 5
6 110 6
7 111 7
Counting in Octal
Decimal Octal Decimal Octal Decimal Octal
8 10 16 20 24 30
9 11 17 21 25 31
10 12 18 22 26 32
11 13 19 23 27 33
12 14 20 24 28 34
13 15 21 25 29 35
14 16 22 26 30 36
15 17 23 27 31 37
Binary-Octal Conversion

• Binary to Octal Conversion


– 11010110101110010110
– 011 010 110 101 110 010 110
–3 2 6 5 6 2 6
• Octal to Binary Conversion
– 1726
– 001 111 010 110
Decimal-Octal Conversion

• Decimal to Octal Conversion


• Indirect Method
– Decimal →Binary → Octal
• Repeated Division by 8
Decimal-Octal Conversion

• Octal to Decimal Conversion


• Indirect Method
– Octal →Binary → Decimal
• Sum-of-Weights
Octal Addition & Subtraction

• Octal Addition
– Carry generated
• Octal Subtraction
– Borrow weight 8
Repeated Division by 8

Number Quotient Remainder


2075 259 3 (O0)
259 32 3 (O1)
8 4 0 (O2)
4 0 4 (O3)
Sum-of-Weights

4033
(4 x 83) + (0 x 82) + (3 x 81) + (3 x 80)
(4 x 512) + (0 x 64) + (3 x 8) + (3 x 1)
2048 + 0 + 24 + 3
2075
Octal Addition

Carry1
7602 2+1=3d 3O
+ 5771 0+7=7d 7O
15573 6+7=13d 15O
1+7+5=13d 15O
Octal Subtraction

Borrow 11
7602 2-1=1d 1O
- 5771 8-7=1d 1O
1611 13-7=6d 6O
6-5=1d 1O

You might also like