0% found this document useful (0 votes)
67 views80 pages

06 - Chapter - 1&5 - Arithmetic - Logic - UJ

The document covers fundamental concepts of binary arithmetic, including binary addition, subtraction, and number representation systems such as signed magnitude, 1's complement, and 2's complement. It explains the processes for performing binary operations and the implications of signed and unsigned numbers. Additionally, it provides examples and challenges related to these concepts, emphasizing the range and representation of numbers in different formats.

Uploaded by

husbanfaisal6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views80 pages

06 - Chapter - 1&5 - Arithmetic - Logic - UJ

The document covers fundamental concepts of binary arithmetic, including binary addition, subtraction, and number representation systems such as signed magnitude, 1's complement, and 2's complement. It explains the processes for performing binary operations and the implications of signed and unsigned numbers. Additionally, it provides examples and challenges related to these concepts, emphasizing the range and representation of numbers in different formats.

Uploaded by

husbanfaisal6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 80

Digital Logic

0907231

Adapted from Dr. Bassam Kahhaleh’ Slides by Prof. Iyad Jafar


Chapter 1
Binary Arithmetic
Chapter 5
Arithmetic Logic
Circuits
Outline
 Binary Addition
 Unsigned Binary Subtraction
 Binary Complements
 Unsigned Numbers
 Signed Numbers
 Binary Adders
 Binary Subtractors
 Overflow Detection
 Binary Multiplication and Division
 Number Width Expansion
3
Binary Addition
Binary Addition
 Remember!
 Decimal Addition

1 1 Carry
5 5
+ 5 5

1 1 0
= Ten ≥ Base
 Subtract a Base and add
carry to next digit
5
Binary Addition
 One bit addition X: Augend
Y: Addend
 Four possible combinations S: Sum
C: Carry
X
+Y
CS
0 0 1 1
+0 +1 +0 +1
0 0 0 1 0 1 1 0

6
Binary Addition
 Multiple bits!
 Column Addition

1 1 1 1 1 1
1 1 1 1 0 1 = 61
+ 1 0 1 1 1 = 23

1 0 1 0 1 0 0 = 84

≥ (2)10
 Subtract a Base and add carry to next
digit
7
Unsigned Binary
Subtraction
Unsigned Binary Subtraction
 One-bit Subtraction 0
 Four possible combinations - 1
? ?
X
- Y 1 02
BD
- 1
0 1 1 Wrong! 1 1
- 0 - 0 - 1
100
0 0 0 1 0 0
- 11
X: Subtrahend Y : Minuend D: Difference B: Borrow -001 9
Unsigned Binary Subtraction

0 02 12
0110 0001
- 0101 - 0101
0001 1100

10000
- 1100
- 0100
10
Unsigned Binary Subtraction
 Borrow a “Base” when needed

1 2 = (10)2
0 2 2 0 0 2
1 0 0 1 1 0 1 = 77
− 1 0 1 1 1 = 23

0 1 1 0 1 1 0 = 54

11
Binary Complements
Complements
 1’s Complement (Diminished Radix Complement)
● All ‘0’s become ‘1’s
● All ‘1’s become ‘0’s
Example (10110000)2
 (01001111)2
If you add a number and its 1’s complement …

10110000
+ 01001111
11111111
13
Complements
 What is the 1s complement of

● (10010111)2

● (100011)2

14
Complements
 2’s Complement (Radix Complement)
● Take 1’s complement then add 1
OR
● Toggle all bits to the left of the first ‘1’ from the right
Example:
Number: 10110000 10110000
1’s Comp.:
01001111
+ 1

01010000 01010000

15
Complements
 What is the 2s complement of

● ( 1010000100 )2

● ( 101111111 )2

16
Unsigned Numbers
Unsigned Numbers
 All numbers considered so far are unsigned
numbers, i.e. positive only
 Given n bits to represent an unsigned number:
● The minimum value is 0
● The maximum value is 2n-1
 Example
●n=9
♦ Minimum =
♦ Maximum =

 How about signed numbers?


18
Signed Numbers
Signed Numbers
 Computers Represent Information in ‘0’s and ‘1’s
● ‘+’ and ‘−’ signs have to be represented in ‘0’s and ‘1’s
♦ ‘0’  positive
♦ ‘1’  negative
● We need one bit; the sign bit
 Three Systems
● Signed Magnitude
● Signed 1’s Complement
● Signed 2’s Complement
 All three use the left-most bit to represent the sign
20
Signed Magnitude Representation
 Magnitude of positive and negative numbers is the
same and in binary.
 Only the sign is different.

S Magnitude (Binary)

0 1101 Positive (+13)

1 1101 Negative (-13)

21
Signed Magnitude Representation
 Using 6 bits, show the representation of (-25)10 in signed
magnitude.

 What is the value of (101001)2 if it is a signed magnitude


number?

 What is the value of (001101)2 if it is signed magnitude


number?

22
Signed Magnitude Representation
 List all signed magnitude numbers that can be represented
using 3 bits and determine their value in decimal.

Signed Magnitude Value in Decimal

0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
23
Signed Magnitude Range
 4-Bit Representation Sign Mag. Decimal
0000 +0
4 0001 +1
2 = 16 Combinations
0010 +2
− 7 ≤ Number ≤ + 7 0011 +3
0100 +4
−23+1 ≤ Number ≤ +23 − 1 0101
0110
+5
+6
0111 +7
1000 −0
 n-Bit Representation 1001 −1
1010 −2
n−1 n−1 1011 −3
−2 +1 ≤ Number ≤ +2 −1 1100 −4
1101 −5
1110 −6
1111 −7
24
Signed Magnitude Representation
 Challenges
● Two representations for 0
(+0)10  (0 000)2
(−0)10  (1 000)2

● Can’t include the sign bit in ‘Addition’

0 0 1 1  (+3)10
+ 1 0 1 1  (−3)10

1 1 1 0  (−6)10
25
1’s Complement Representation
 Positive numbers: magnitude in binary with a sign bit of 0
 Negative numbers: calculate the “1’s Comp.” of the positive
number including the sign bit

0 Magnitude (Binary) Positive


Sign

1 Code (1’s Comp.) Negative

26
1’s Complement Representation
 Using 6 bits, show the representation of (-25)10 in signed 1s
complement.

 What is the value of (101001)2 if it is a signed 1s


complement?

 What is the value of (001101)2 if it is signed 1s complement


number?

27
1’s Comp. Representation
 List all signed 1’s comp numbers that can be represented
using 3 bits and determine their value in decimal.

Signed 1s Comp. Value in Decimal

0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
28
1’s Complement Range
 4-Bit Representation 1s Comp. Decimal
0000 +0
4 0001 +1
2 = 16 Combinations
0010 +2
− 7 ≤ Number ≤ + 7 0011 +3
0100 +4
−23+1 ≤ Number ≤ +23 − 1 0101
0110
+5
+6
0111 +7
1000 −7
 n-Bit Representation 1001 −6
1010 −5
n−1 n−1 1011 −4
−2 +1 ≤ Number ≤ +2 −1 1100 −3
1101 −2
1110 −1
1111 −0
29
1’s Comp. Representation
 Challenges
● Two representations for 0
(+0)10  (0 000)2
(−0)10  (1 111)2

● We can add the sign bit, but we may need to correct the
result of ‘Addition’ unless we add the carry
0 0 1 1  (+3)10
1 + 1 1 0 1  (−2)10
0 0 0 0  (+0)10 X
1
0 0 0 1  (+1)10 30
2’s Complement Representation
 Positive numbers: magnitude in binary with a sign bit of 0
 Negative numbers: calculate the “2’s Comp.” of the positive
number including the sign bit

0 Magnitude (Binary) Positive


Sign

1 Code (2’s Comp.) Negative

31
2’s Complement Representation
 Using 6 bits, show the representation of (-25)10 in 2s
complement.

 What is the value of (101001)2 if it is a signed 2s


complement number?

 What is the value of (001101)2 if it is signed 2s complement


number?

32
2’s Complement Representation
 List all signed 2’s comp numbers that can be represented
using 3 bits and determine their value in decimal.

Signed 2s Comp. Value in Decimal

0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
33
2’s Complement Range
 4-Bit Representation 2s Comp. Decimal
0000 +0
4 0001 +1
2 = 16 Combinations
0010 +2
− 8 ≤ Number ≤ + 7 0011 +3
0100 +4
−23 ≤ Number ≤ + 23 − 1 0101
0110
+5
+6
0111 +7
1000 −8
 n-Bit Representation 1001 −7
1010 −6
n−1 1011 −5
−2 ≤ Number ≤ + 2
n−1
−1 1100 −4
1101 −3
1110 −2
1111 −1
34
2’s Complement Representation
 Challenges???
● One representation for 0
(+0)10  (0 000)2
(−0)10  (0 000)2  (1 111) 2 +1  1 (0 000) 2
● We can add the sign bit with no problems; result is
always correct!
0 0 1 1  (+3)10
1 + 1 1 1 0  (−2)10
0 0 0 1  (+1)10

35
Number Representations Summary
 4-Bit Example
Unsigned Signed
1’s Comp. 2’s Comp.
Binary Magnitude

Range 0 ≤ N ≤ 15 -7 ≤ N ≤ +7 -7 ≤ N ≤ +7 -8 ≤ N ≤ +7

0 0 0
Positive
Binary Binary Binary Binary

1 1 1
Negative X
Binary 1’s Comp. 2’s Comp.
36
Example
 What is the decimal value of (101110)2?

37
Example
 Complete the following table. Assume you have 5 bits only.
Decimal Signed. Mag. Signed 1’s Comp. Signed 2’s Comp.

+12
-12
+7
-7
+19
-19
+16
-16 38
Example
 Complete the following table. Assume you have 5 bits only.
Decimal Signed. Mag. Signed 1’s Comp. Signed 2’s Comp.

+12 0 1100 0 1100 0 1100


-12 1 1100 1 0011 1 0100
+7 0 0111 0 0111 0 0111
-7 1 0111 1 1000 1 1001
+19 Out of range Out of range Out of range
-19 Out of range Out of range Out of range
+16 Out of range Out of range Out of range
-16 Out of range Out of range 1 0000 39
Binary Subtraction Using 1’s Comp. Addition
 Change “Subtraction” to “Addition”
 If “Carry” = 1 (5)10 – (1)10 (5)10 – (6)10
then add it to the (+5)10 + (-6)10
(+5)10 + (-1)10
LSB.
 If “Carry” = 0 0101 0101
then the result + 1110 + 1001
is ready.
1 0011 0 1110
+

0100 1110

+4 −1 40
Binary Subtraction Using 2’s Comp. Addition
 Change “Subtraction” to “Addition”
 We ignore the carry (5)10 – (1)10 (5)10 – (6)10
in the 2’s Complement. (+5)10 + (-1)10 (+5)10 + (-6)10
0101 0101
+ 1111 + 1010

1 0100 0 1111

+4 −1

41
Binary Adders
Binary Adders
 Imagine designing a circuit that adds two n-bit
numbers
● Number of inputs 2 × n
● Number of combinations 22n
● Number of outputs n
 Complex as n increases!
 Alternatives? C C C2 C1
4 3

X3 X2 X1 X0
Y3 Y2 Y1 Y0
+

S3 S2 S1 S0
43
Binary Adders
 Design a functional block for the sub-function and
repeat to obtain functional block for overall function
 This functional block is called Cell
 The approach is called Iterative Circuit / Array
 Iterative array takes advantage of the regularity to
make design feasible
A n-1B n-1 A1 B0

X n-1 X2 X1
Xn X0
Cell n-1 Y n-1 Y2 Cell 1 Y1 Cell 0
Yn Y0

Cn-1 C1 C0
44
Binary Adder
 Half Adder
● Adds 1-bit plus 1-bit x
x S
+ y HA
● Produces Sum and Carry y C
───
C S

x y C S
0 0 0 0 x S
0 1 0 1
1 0 0 1 C
y
1 1 1 0

45
Example 5
 Using 1-bit half adders, show how to build a 2-bit
adder C2 C1
X
X1 X0 0
X1 2-bit
S0

Y1 Y0 + S
Y0 Adder 1
C2
Y1
S1 S0

X0 S0
Y0
HA C1 X1+C1
HA Y1+X1+C1
X1 S1
HA
Y1

C2
46
Exercise
 Using 1-bit half adders, show how to build a 4-bit
adder

47
Exercise
 Using the 2-bit adder block in Example 5, show how to
build a 4-bit adder to add two 4-bit numbers
A: A3A2A1A0 and B: B3B2B1B0

Y1 Y 0 X1 X 0 Y 1 Y0 X1 X0

Adder
Adder

2-bit
2-bit

Cout S1 S0 Cout S1 S 0

48
Binary Adder
 Full Adder x
+ y x
● Adds 1-bit plus 1-bit plus 1-bit S
+ Cin y FA
─── Cin Cout
● Produces Sum and Carry
Cout S
x y Cin Cout S y

0 0 0 0 0 0 1 0 1
0 0 1 0 1 x 1 0 1 0
0 1 0 0 1 Cin
0 1 1 1 0 S = x'y'Cin+x'yCin'+xy'Cin'+xyCin = x  y  Cin
y
1 0 0 0 1
1 0 1 1 0 0 0 1 0
1 1 0 1 0 x 0 1 1 1
1 1 1 1 1 Cin
Cout = xy + xCin + yCin
49
Binary Adder
 Full Adder S = x'y'Cin+x'yCin'+xy'Cin'+xyCin = x  y  Cin
Cout = xy + xCin + yCin

x
S S
x
y y
Cout
Cin
Cin
Cout

50
Example 6
 Using 1-bit full adders, show how to build a 4-bit
adder xxxx yyyy 3 2 1 0 3 2 1 0

c 3 c 2 c1 .
+ x 3 x2 x1 x0 4-bit
+ y 3 y2 y1 y0 C4
Binary Adder 0
────────
C4 S3 S2 S1 S0
S3S2S1S0
x3 x2 x1 x0
y3 y2 y1 y0
0
Carry
Propagate
FA FA FA FA Adder
Or Ripple
Carry
C4 C3 C2 C1 Adder
51
S S S S
Example 7
 8-bit adder realized using two 4-bit CPAs

x7 x6 x5 x4 x3 x2 x1 x0
y7 y6 y5 y4 y3 y2 y1 y0 +
S7 S6 S5 S4 S3 S2 S1 S0
x7 x6 x5 x4 y7 y6 y5 y4 x3 x2 x1 x0 y3 y2 y1 y0

A3 A2 A1 A0 B3 B2 B1 B0 A3 A2 A1 A0 B3 B2 B1 B0
4-bit Ripple Carry 4-bit Ripple Carry
C8 C4 Adder C0 C4 Adder C0 0
S3 S2 S1 S0 S3 S2 S1 S0

S7 S6 S5 S4 S3 S2 S1 S0
52
Real Stuff
 74LS83A
 4-BIT BINARY FULL ADDER (Fast Carry)

53
Binary Subtractors
Binary Subtractor
 Use 2’s complement with binary adder
● x – y = x + (-y) = x + y’ + 1

x3 x2 x1 x0 y3 y2 y1 y0

A3 A2 A1 A0 B3 B2 B1 B0
Cy Binary Adder Ci 1
S3 S2 S1 S0

F3 F2 F1 F0 55
Binary Adder/Subtractor
 Use single adder for addition and subtraction
 M: Control Signal (Mode)
● M=0F=x+y
● M=1F=x–y

56
Binary Adder/Subtractor
 Can you think of a different approach to build the
adder/subtractor?
● Multiplexors!

57
Exercise
 Design the circuit that can perform the operations X+Y, X-
Y, Y-X and –X-Y. Assume X and Y to be 4-bit numbers.
● Can we preform the four operations using one 4-bit adder?

● Only three operations can be implemented using a single adder


● Need two adders  Two possible solutions
58
Exercise - continued
 Two possible solutions

59
Overflow Detection
Overflow
 Arithmetic operations are performed on fixed-size
values.
 Result might not fit in the given size!

1 1 1 1
1 0 1 1
1 1 1 1
+

No space to 1 0 1 0
store!

 Need to detect overflow in hardware!


61
Overflow
 Unsigned Binary Numbers

0 0 0 1 1 1 0 1 1 1
1 0 0 1 + 1 1 0 1 +
1 1 0 0 0 1 0 0
x3 x2 x1 x0
y3 y2 y1 y0
0

FA FA FA FA

Overflow C4 C3 C2 C1
S3 S2 S1 S0

62
Overflow
 Signed 2’s Complement Numbers
x3 x2 x1 x0
y3 y2 y1 y0
0

FA FA FA FA

Overflow C4 C3 C2 C1
S3 S2 S1 S0
 How?

63
Overflow
 8-bit signed number range between: -128 to +127

(+70) 01000110 (-70) 10111010


+ + + +
(+80) 01010000 (-80) 10110000
0 10010110 (-106) 1 01101010 (+106)

(+70) 01000110 (-70) 10111010


- + - +
(-80) 01010000 (+80) 10110000
0 10010110 (-106) 1 01101010 (+106)

64
Multiplication and
Division
Binary Multiplication
 Single-bit multiplication
0×0=0 0×1=0 1×0=0 1×1=1
 Multiple bits
101 Multiplicand
× 010 Multiplier
000 Partial Product
1010
+ 00000
01010 Product

66
Multiplication by a Constant
 Can use an adder of suitable size to implement
 Example: X3X2X1X0 × 101
X3 X2 X1 X0
X3 X2 X3 X2 0 0 X1 X0 1 0 1 ×
X3 X2 X1 X0
0 0 0 0 0 0
X3 X2 X1 X0 0 0
X0
(X2+X0)
(X3+X1)

X1
(X3+0)
(X2+0)

(X3+X1)

(X2+X0)
(X2+0)
(X3+0)
X1 X0

67
Multiplication by 2n

0 0 1 1 3
×21
x 0 1 1 0 0 6 ×22
×21
x 1 1 0 0 0 12

 Multiplication by 2n is equivalent to shifting the


multiplicand by n bits to the left and inserting n zeros from
right 68
Division By 2n (Logical Right Shift)

1 1 0 0 12
/21
0 0 1 1 0 x 6 /22
/21
0 0 0 1 1 x 3
 Division by 2n is equivalent to shifting the dividend by
n bits to the right and inserting n zeros from left
 Use with unsigned numbers 69
Division By 2n (Arithmetic Right Shift)

1 1 0 0 -4
/21
1 1 1 1 0 x -2 /22
/21
1 1 1 1 1 x -1
 Division by 2n is equivalent to shifting the dividend by n
bits to the right and replicating the sign bit n times on the
left
 Use with signed numbers 70
Exercise
 Assume A is 6-bit number with value (101110)2
● What is the decimal value of A if it is
♦ An unsigned number 
♦ Signed magnitude number 
♦ Signed 1s complement number 
♦ Signed 2s complement number 
● If A undergoes a logical right shift by two bits, then what is its new
decimal value?

● If A undergoes an arithmetic right shift by two bits, then what is its


new decimal value?

71
Number Width
Expansion
Zero Fill
 Given an M-bit number, we might need to make it
an N-bit number such that N > M

1 1 0 1 13

0 0 0 0 1 1 0 1 13

 Zero filling: add N-M zeros to the left


 Used with unsigned numbers

73
Sign Extension
 Given an M-bit number, we might need to make it
an N-bit number such that N>M
1 0 1 1 -5

1 1 1 1 1 0 1 1 -5

0 0 1 1 +3

0 0 0 0 0 0 1 1 +3
 Replicate the sign bit N-M times
 Used with signed numbers
74
Exercises
Suggested Problems
 1-8
 1-12
 5-8
 5-13

76
Exercises
* Obtain the 1’s and 2’s complements of the following binary
numbers:
(a) 11101010
(b) 01111110
(c) 00000001
(d) 10000000
(e) 00000000

77
Exercises
* Implement a full adder with two 4  1 multiplexers

78
Exercises
* Convert decimal +61 and +27 to binary using the signed-2’s
complement representation and enough digits to accommodate the
numbers.

Then perform the binary equivalent of (+27) + (– 61), (–27) +


(+61) and (–27) + (–61). Convert the answers back to decimal and
verify that they are correct.

79
Exercises
* The adder-subtractor circuit has the following values for
mode input M and data inputs A and B. In each case,
determine the values of the four SUM outputs and the carry
C.
M A B
(a) 0 0111 0110
(b) 0 1000 1001
(c) 1 1100 1000
(d) 1 0101 1010
(e) 1 0000 0001

80

You might also like