0% found this document useful (0 votes)
20 views51 pages

Digital Logic Design (ES216) Lec 7-8

Uploaded by

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

Digital Logic Design (ES216) Lec 7-8

Uploaded by

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

Digital Logic Design (ES216)

Department of Mechatronic
Engineering

Lec # 7-8

Engr. Muhammad Arsalan Jalees


Abro

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)

So, when the sum of a column is equal


to or greater than the base, we subtract
the base from the sum, record the
difference, and carry the tenth to the
next column to the left.
Binary Arithmetic
• Binary arithmetic is essential in all digital computers and in many
other types of digital systems.
• Types of Binary Arithmetic:
• Addition
• Subtraction
• Multiplication
• Division
Binary Addition
• The four basic rules for adding binary digits (bits) are as follows:

• 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

27 00011011 172 10101100


- 10 + 00001010 - 42 - 00101010
17 00010001 130 10000010

9 1001 192 11000000


- 4 + 0100 - 3 - 00000011
5 0101 189 10111101
Binary multiplication
• The four basic rules for multiplying bits are as follows:
How to carry out binary multiplication?
• Multiplication is performed with binary numbers in the same manner as with decimal numbers.
• It involves forming partial products, shifting each successive partial product left one place, and
then adding all the partial products.

*Multiply 1010 x 1101


Binary division
• Division in binary follows the same procedure as division in decimal.
Practice problems
1. Perform the following binary additions:
(a) 111 + 100 (b) 11011 + 10110
2. Perform the following binary subtractions:
(a) 1111 - 0110 (b) 1011 - 0111
3. Perform the indicated binary operations:
(a) 1101 * 1010 (b) 1100 ÷ 011
Complements of Binary Numbers
• In mathematics, positive numbers (including zero) are represented as
unsigned numbers.
• when dealing with negative numbers, we use a -ve sign in front of the
number.
• This is true with signed binary numbers.
• However, in digital circuits there is no provision made to put a plus or
minus sign to a number.
• We know that binary digits, or bits only have two values, either a “1” or a
“0” and conveniently, a sign also has only two values, being a “+” or a “–“.
• For signed binary numbers the most significant bit (MSB) is used as the
sign bit.
*bit (being a
• If the sign bit is “0”, this means the number is positive in value. If the sign
contraction
bit is “1”, then the number is negative in value. of BInary digiT)
Disadvantage of signed bit
• Unsigned binary number utilizes the full range n-bit, but for signed binary number, we
have an n-1 bit giving a reduced range of digits from:
• -2(n-1) to +2(n-1)
• So, for example: if we have 4 bits to represent a signed binary number, (1-bit for the Sign
bit and 3-bits for the Magnitude bits), then the actual range of numbers we can represent
in sign-magnitude notation would be:
• -2(4-1) – 1 to +2(4-1) – 1
• -2(3) – 1 to +2(3) – 1
• -7 to +7
• 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.
Decimal to signed binary conversion
Convert the following decimal values into signed binary numbers using
the sign-magnitude format:
-1510 as a 6-bit number ⇒ 1011112

+2310 as a 6-bit number ⇒ 0101112

-5610 as a 8-bit number ⇒ 101110002

+8510 as a 8-bit number ⇒ 010101012

-12710 as a 8-bit number ⇒ 111111112


Complements of Binary Numbers
• The 1’s complement and the 2’s complement of a binary number are
important because they permit the representation of negative numbers.
• The method of 2’s complement arithmetic is commonly used in
computers to handle negative numbers
1’s Complement
The 1’s complement of a binary number is found by changing all 1s to 0s and all 0s
to 1s, as illustrated below:

The simplest way to obtain the 1’s


complement of a binary number with a
digital circuit is to use parallel inverters
(NOT circuits)
1’s complement
• Positive numbers in 1’s complement form are represented the same way as the
positive sign-magnitude numbers.
• Negative numbers, however, are the 1’s complements of the corresponding
positive numbers.
• For example, using eight bits, the decimal number 225 is expressed as the 1’s
complement of +25 (00011001) as 11100110.

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:

11011000 1’s complement


+ 1
11011001 2’s complement
Task

Why use 2’s complement?


Convert from 1’s complement or 2’s complement back to
original
To convert from a 1’s or 2’s complement back to the true
(uncomplemented) binary form, use the same two procedures described
previously.
To go from the 1’s complement back to true binary, reverse all the bits
i.e. use inverter on the 1’s complement.
To go from the 2’s complement form back to true binary, take the 1’s
complement of the 2’s complement number and add 1 to the least
significant bit or start from the LSB and group together the bits leading
to the first 1 and take the 1’s complement of the rest of the bits.
Example
Example: Convert +3510 to two’s complement.

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

True Binary = 0010 0011


One’s complement = 1101 1100
Add 1 = +1
Two’s complement =1101 1101
Example
• Example: Convert 1101 1101 two’s complement back to decimal. The
sign bit is 1 therefore it will be a negative number.

Two’s complement =1101 1101


Complement =0010 0010
Add 1 = +1
True binary =0010 0011
Decimal Equivalent = -35
Homework

• Study the Hexadecimal and Octal mathematical operations.


Addition of signed numbers
• The two numbers in an addition are the addend and the augend. The
result is the sum.
• There are four cases that can occur when two signed binary numbers
are added.
1. Both numbers positive
2. Positive number with magnitude larger than negative number
3. Negative number with magnitude larger than positive number
4. Both numbers negative
Addition of signed numbers cases:

The sum is positive and is therefore in true (uncomplemented) binary.

The final carry bit is discarded. The sum is positive and therefore in true (uncomplemented) binary.
Addition of signed numbers cases:

The sum is negative and therefore in 2’s complement form.

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).

• Adding signed positive 125 with signed positive results in


signed negative 183.
Addition of more than one number
Add the signed numbers: 01000100, 00011011, 00001110, and 00010010.
Subtraction of signed numbers
• Subtraction is a special case of addition.
• For example, subtracting +6 (the subtrahend) from +9 (the minuend)
is equivalent to adding -6 to +9.
• The result of subtraction is called the difference.
• The sign of the difference is the sign of the largest number.
• When you take the 2’s complement of the negative number 11101101
(-19), you get 00010011, which is +19.
Examples of subtraction of signed numbers
Perform each of the following subtractions of the signed numbers:
(a) 00001000 - 00000011 (b) 00001100 - 11110111
Multiplication of signed numbers
• The numbers in multiplication are the
multiplicand, the multiplier, and the product.
• There are two methods: Direct addition and
partial products.
• In direct addition, just keep adding the number to itself
until the desired multiple is achieved.

For example: Multiply the binary signed numbers,


01001101 (multiplicand) and 00000100 (multiplier)
Multiplication of signed numbers (partial products method)
The basic steps in the partial products method of binary multiplication are as follows:
Step 1: Determine if the signs of the multiplicand and multiplier are the same or different. This
determines what the sign of the product will be.
Step 2: Change any negative number to true (uncomplemented) form. Because most computers
store negative numbers in 2’s complement, a 2’s complement operation is required to get
the negative number into true form.
Step 3: Starting with the least significant multiplier bit, generate the partial products. When the
multiplier bit is 1, the partial product is the same as the multiplicand. When the multiplier
bit is 0, the partial product is zero. Shift each successive partial product one bit to the
left.
Step 4: Add each successive partial product to the sum of the previous partial products to get the
final product.
Step 5: If the sign bit that was determined in Step 1 is negative, take the 2’s complement of the
product. If positive, leave the product in true form. Attach the sign bit to the product.
Example
Multiply the signed binary numbers: 01010011 (multiplicand) and
11000101 (multiplier).
Division of signed numbers
• The numbers in a division are the dividend, the divisor, and the quotient.
• The basic steps in a division process are as follows:
Step 1: Determine if the signs of the dividend and divisor are the same or different. This
determines what the sign of the quotient will be. Initialize the quotient to zero.
Step 2: Subtract the divisor from the dividend using 2’s complement addition to get the first
partial remainder and add 1 to the quotient. If this partial remainder is positive, go to
step 3. If the partial remainder is zero or negative, the division is complete.
Step 3: Subtract the divisor from the partial remainder and add 1 to the quotient. If the result
is positive, repeat for the next partial remainder. If the result is zero or negative, the
division is complete.
Example
Divide 01100100 by 00011001.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy