Digital Logic Design (ES216) Lec 7-8
Digital Logic Design (ES216) Lec 7-8
Department of Mechatronic
Engineering
Lec # 7-8
arsalan.abro@faculty.muet.edu.pk
Lecture contents
• Binary Addition
• Binary Subtraction
• Binary Multiplication
• Binary Division
• Signed and unsigned binary numbers
• 1’s Complement
• 2’s Complement
• Arithmetic Operations of Signed Binary Numbers
• BCD Addition
• Gray Code
• BCD to Gray and Gray to BCD conversion
Basic decimal addition (revision)
• When binary numbers are added, the last condition creates a sum of 0
in a given column and a carry of 1 over to the next column to the left
Binary Addition Rules
:
▪0+0 =0
▪0+1 =1 (just like in decimal)
▪1+0 =1
◼ 1+1 = 210 =
= 102 = 0 with 1 to carry
◼ 1+1+1 = 310 =
= 112 = 1 with 1 to carry
Addition of binary bits
• In the right column, 1 + 1 = 0 with a carry of 1 to the next
column to the left.
• In the middle column, 1 + 1 + 0 = 0 with a carry of 1 to the
next column to the left.
• In the left column, 1 + 0 + 0 = 1.
• When there is a carry of 1, you have a situation in which
three bits are being added (a bit in each of the two numbers
and a carry bit). This situation is illustrated as follows:
Binary addition examples
The equivalent decimal addition is also shown for reference.
Binary subtraction
• The four basic rules for subtracting bits are as follows:
Binary subtraction explanation
▪ In binary, the base unit is 2
▪ So, when you cannot subtract, you borrow from the column to the left.
▪ The amount borrowed is 2 (1 0 in binary).
▪ The 2 is added to the original column value, so you will be able to subtract.
Examples
(c)
Explanation of binary subtraction
Some more examples
In the 1’s complement form, a negative number is the 1’s complement of the
corresponding positive number.
2’s Complement
• The 2’s complement of a binary number is found by adding 1 to the
LSB of the 1’s complement.
2’s complement = (1’s complement) + 1
2’s complement
• Positive numbers in 2’s complement form are represented the same way as
in the sign-magnitude and 1’s complement forms.
• Negative numbers are the 2’s complements of the corresponding positive
numbers.
• Again, using eight bits, let’s take decimal number 225 and express it as the
2’s complement of +25 (00011001). Inverting each bit and adding 1, you get
-25 = 11100111
In the 2’s complement form, a negative number is the 2’s complement of the
corresponding positive number.
Alternative method for 2’s complement
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 complements of the remaining bits.
2’s complement circuit
The 2’s complement of a negative binary number can be realized using inverters and an
adder.
This illustrates how an 8-bit number can be converted to its 2’s complement by first
inverting each bit (taking the 1’s complement) and then adding 1 to the 1’s complement
with an adder circuit.
Example
Express the decimal number 39 as an 8-bit number in the sign-magnitude, 1’s
complement, and 2’s complement forms.
Solution
First, write the 8-bit number for +39.
00100111
In the sign-magnitude form, 239 is produced by changing the sign bit to a 1 and leaving the
magnitude bits as they are.
10100111
In the 1’s complement form, 239 is produced by taking the 1’s complement of +39 (00100111).
11011000
Example (CONt.)
In the 2’s complement form, 239 is produced by taking the 2’s complement of +39 (00100111) as
follows:
2 35 1
2 17 1 True Binary = 0010 0011
2 8 0 Two’s complement = ??
2 4 0
2 2 0
1
Example
Example: Convert -3510 to two’s complement
The final carry bit is discarded. The sum is positive and therefore in true (uncomplemented) binary.
Addition of signed numbers cases:
The final carry bit is discarded. The sum is negative and therefore in 2’s complement form.
Overflow Condition
• When two numbers are added and the number of bits required to
represent the sum exceeds the number of bits in the two numbers, an
overflow results.
• This is indicated by an incorrect sign bit.
• Overflow Condition: An overflow can occur only when BOTH
NUMBERS are positive or BOTH NUMBERS are negative.
• If the sign bit of the result is DIFFERENT than the sign bit of the
numbers that are added, overflow is indicated.
Overflow example
• Adding 7 + 1 in 4-Bit must be equal to 8.
• But 8 cannot be represented with 4 bit 2’s complement number
as it is out of range (as one bit is reserved for sign).
• Two Positive numbers were added and the answer we got is
negative 8 (-8).