0% found this document useful (0 votes)
16 views35 pages

Untitled (1)

Uploaded by

searchmeshivam21
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)
16 views35 pages

Untitled (1)

Uploaded by

searchmeshivam21
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/ 35

Chapter 3 Complements

Subtraction using addition


■ Conventional addition (using carry) is easily
■ implemented in digital computers.
■ However; subtraction by borrowing is difficult
and inefficient for digital computers.
■ Much more efficient to implement subtraction
using ADDITION OF the COMPLEMENTS of
numbers.
Complements of numbers
(r-1 )’s Complement
•Given a number N in base r having n digits,
•the (r- 1)’s complement of N is defined as
(rn - 1) - N

•For decimal numbers the base


or r = 10 and r- 1= 9, 9 9 9 9 9
•so the 9’s complement of N is
(10n-1)-N - Digit
n
Digit
n-1
Next
digit
Next
digit
First
digit

•99999……. - N
9’s complement Examples
9 9 9 9 9 9

2- Find the 9’s complement of 546700 and 12389 - 5 4 6 7 0 0

The 9’s complement of 546700 is 999999 - 546700= 4 5 3 2 9 9


453299

and the 9’s complement of 12389 is 9 9 9 9 9


99999- 12389 = 87610.
- 1 2 3 8 9

8 7 6 1 0
r’s Complement
•Given a number N in base r having n digits,
•the r’s complement of N is defined as
rn - N.

•For decimal numbers the base


or r = 10,
1 0 0 0 0 0
•so the 10’s complement of N
is 10n-N. - Digit
n
Digit
n-1
Next
digit
Next
digit
First
digit

•100000……. - N
10’s complement Examples
Find the 10’s complement of
546700 and 12389 1 0 0 0 0 0 0

The 10’s complement of 546700 - 5 4 6 7 0 0

is 1000000 - 546700= 453300


4 5 3 3 0 0
and the 10’s complement of
12389 is 1 0 0 0 0 0
100000 - 12389 = 87611.
- 1 2 3 8 9
Notice that it is the same as 9’s
8 7 6 1 1
complement + 1.
l’s complement
■ For binary numbers, r = 2 and r — 1 =
1,
■ r-1’s complement is the l’s complement.
■ The l’s complement of N is (2n - 1) - N.

Bit n-1 Bit n-2 ……. Bit 1 Bit 0

1 1 1 1 1

- Digit
n
Digit
n-1
Next
digit
Next
digit
First
digit
l’s complement

Find r-1 complement for binary number N with four binary digits.
r-1 complement for binary means 2-1 complement or 1’s complement.
n = 4, we have 24 = (10000)2 and 24 - 1 = (1111)2.
The l’s complement of N is (24 - 1) - N. = (1111) - N
l’s complement (Replace 0 by
1 and vice-versa)

The complement 1’s of


- 1 0 1 1 0 0 1

1011001 is 0100110 0 1 0 0 1 1 0

The 1’s complement of


- 0 0 0 1 1 1 1

0001111 is 1110000 1 1 1 0 0 0 0
2’s complement

For binary numbers, r = 2,


r’s complement is the 2’s complement.
The 2’s complement of N is 2n - N.

1 0 0 0 0 0

- Digit
n
Digit
n-1
Next
digit
Next
digit
First
digit
2’s complement Example
1 0 0 0 0 0 0 0

The 2’s complement of


1011001 is 0100111
- 1 0 1 1 0 0 1

0 1 0 0 1 1 1

1 0 0 0 0 0 0 0
The 2’s complement of
0001111 is 1110001
- 0 0 0 1 1 1 1

1 1 1 0 0 0 1
Fast Methods for 2’s
Complement

Method 1:
The 2’s complement of binary number is obtained by adding 1 to the
l’s complement value.
Example:
1’s complement of 101100 is 010011 (invert the 0’s and 1’s)
2’s complement of 101100 is 010011 + 1 = 010100
Fast Methods for 2’s
Complement

Method 2:
The 2’s complement can be formed by leaving all least significant 0’s
and the first 1 unchanged, and then replacing l’s by 0’s and 0’s by l’s
in all other higher significant bits.

Example:
The 2’s complement of 1101100 is
0010100
Leave the two low-order 0’s and the first 1 unchanged, and then
replacing 1’s by 0’s and 0’s by 1’s in the four most significant bits.
Examples
– Finding the 2’s complement of (01100101)2
• Method 1 – Simply complement each bit and then
add 1 to the result.
(01100101)2
[N] = 2’s complement = 1’s complement (10011010)2 +1
=(10011011)2
• Method 2 – Starting with the least significant bit,
copy all the bits up to and including the first 1 bit
and then complement the remaining bits.
N =01100101
[N] =10011011
How To Represent Signed
Numbers
■ Plus and minus signs used for decimal
numbers: 25 (or +25), -16, etc.

■ For computers, it is desirable to represent


everything as bits.

■ Three types of signed binary number


representations:
1. signed magnitude,
2. 1’s complement, and
3. 2’s complement
1. signed magnitude
• In each case: left-most bit
indicates sign: positive (0) or
negative (1).

Consider 1. signed magnitude:

000011002 = 1210 100011002 = -1210

Sign bit Magnitude Sign bit Magnitude


2. One’s Complement
Representation
■ The one’s complement of a binary
number involves inverting all bits.

• To find negative of 1’s complement number take


the 1’s complement of whole number excluding
the sign bit.

100011002 = 1210 111100112 = -1210

Sign bit Magnitude Sign bit 1’complement


3. Two’s Complement
Representation
• The two’s complement of a binary
number involves inverting all bits and
adding 1.
■ To find the negative of a signed number
take the 2’s the 2’s complement of the
positive number excluding the sign bit.

100011002 = 1210 111101002 = -1210

Sign bit Magnitude Sign bit 2’s complement


Subtraction of Unsigned Numbers
using r’s complement
■ (1) if M ≥ N, ignore the carry without
taking complement of sum.
Subtraction of Unsigned Numbers
using r’s complement
Subtract N from M : M – N:
(Case1) if M ≥ N, ignore the carry without taking
complement of sum.
1. Find r’s complement of N (negative number)
2. Add M to r’s complement
3. ignore the carry without taking complement of
sum.


(Case 2) if M < N, take the r’s complement of
sum and place negative sign in front of sum.
The answer is negative.

1. Find r’s complement of N (negative number)


2. Add M to r’s complement of N

3. No end carry will be generated. Answer will be


negative and in r’s complement form. To get the
original answer, take the r’s complement of answer and
put a negative sign before it.
Example 1 (Decimal unsigned numbers),

perform the subtraction 72532 - 13250 = 59282.

M > N : “Case 1” “Do not take complement of sum


and discard carry”
The 10’s complement of 13250 is 86750.
Therefore:
M= 72532
10’s complement of N =+86750
Sum= 159282
Discard end carry
Answer = 59282 no complement
Example 2;
Now consider an example with M <N.
The subtraction 13250 - 72532 produces negative 59282. Using
the procedure with complements, we have

M = 13250
10’s complement of N = +27468
Sum = 40718

Take 10’s complement of Sum = 100000


-40718
The number is : 59282
Place negative sign in front of the number: -59282
Overflow
• An overflow cannot occur after an addition if
one number is positive and the other is
negative, since adding a positive number to a
negative number produces a result that is
smaller than the larger of the two original
numbers.

■ An overflow may occur if the two numbers


added are both either positive or negative.
Overflow
• The detection of an overflow after the addition of two binary
numbers depends on whether the considered numbers are
signed or unsigned.
• When two unsigned numbers are added, an overflow is
detected from the end carry out of the most significant
position.
• In the case of signed numbers, the leftmost bit always
represents the sign.
• When two signed numbers are added, the sign bit is treated
as part of the number and the end carry does not indicate an
overflow. The end carry acts as the sign bit.
Overflow
■ Example
Decimal Fixed Point
Representation
■ A 4 bit decimal code requires 4 Flip Flops (FF)
■ Representation of 4385 in BCD requires 16

FFs
0100 0011 1000 0101
Decimal representation wasting a considerable
amount of storage space and circuitry
required to perform arithmetic are more
complex. However it’s much more easier than
converting decimal number in binary.
BCD Addition
Step 1 − Perform addition of two BCD numbers by following the rules
of binary addition.
Step 2 − If the result or sum is a 4-bit binary number which is less
than or equal to 9, then the sum is a valid BCD number.
Step 3 − If the sum is a 4-bit number that is greater than 9 or if a
carry is generated, then it is an invalid sum.
Step 4 − To obtain the corrected result/sum, add 6 (0110) to the 4-bit
invalid sum. If a carry is generated when 6 is added, then propagate
and add this carry to the next 4-bit group. This step is done to skip
the six illegal BCD codes (i.e. 1010, 1011, 1100, 1101, 1110, and
1111).
BCD Addition Ex.
• (678)10 = 0110 0111 1000
• (535)10 = 0101 0011 0101
1011 1010 1101
110 110 110
0001 0010 0001 0011
=(1213)10
BCD Subtraction USING 10’s
Complement
A positive number in BCD is represented by 0000 and negative by 1001.
Ex.
375-240= 375+(-240)
-240 is represented in 10’s Complement form=999-240+1=759+1=760
Addition is done by adding all digits including the sign bit and discarding the
carry.
If there is no carry, result is presented by taking 10’s complement once again
and negative sign is added.
BCD Subtraction USING 10’s
Complement
A positive number in BCD is represented by 0000 and negative by 1001.
Ex.
240-375= 240+(-375)
-375 is represented in 10’s Complement form=999-375+1=624+1=625

0240 0000 0010 0100 0000


9625 1001 0110 0010 0101
9865 1001 1000 0110 0101
No carry after addition, so result is negative and to get final answer, take the
10’s complement of the result obtained.
9999-9865+1 = -135
Floating-Point Representation

+ 6132.789 is represented in floating-point with a


fraction and an exponent as follows:

Fraction Exponent
+0.6132789 +04

Scientific notation : + 0.6132789 × 10+4


Floating-Point Representation
Floating point is always interpreted as: m × re
Floating point binary number uses base 2 for the exponent.

For example:
Binary number +1001.11
Fraction(8 bits) Exponent (6 bits)
01001110 000100

The fraction has a 0 in the leftmost position to denote positive.


m × 2e = + (.1001110)2 × 2+4
Floating-Point Representation
■ A floating-point number is said to be normalized if
the most significant digit of the mantissa is nonzero.

■ For example:
■ (1) 350 is normalized but 00035 is not.
■ (2) The 8-bit binary number 00011010 is not. It can
be normalized by shifting decimal point to obtain
11010000.
Floating-Point Representation
■ 32-bit floating point format.
■ Leftmost bit = sign bit (0 positive or 1 negative).
■ Exponent in the next 8 bits.
■ Final portion of word (23 bits in this example) is the
significand (sometimes called mantissa).

You might also like