• No results found

The r’s Complement

N/A
N/A
Protected

Academic year: 2022

Share "The r’s Complement"

Copied!
21
0
0

Loading.... (view fulltext now)

Full text

(1)

BLE 201

DIGITAL ELECTRONICS

COMPLEMENTS

The r’s Complement

The (r −1)’s Complement

(2)

Complements

➢ Complements are used in digital computers for simplifying the subtraction operation and for logical manipulations.

➢ There are two types of complements for each system:

❖ the r's complement and

❖ the (r −1)'s complement.

➢ When the value of the base is substituted, the two types receive the names 2's and 1's Complement for binary numbers, or 10's and 9's complement for decimal numbers.

(3)

The r’s Complement

➢ Given a positive number N in base r with an integer part of n digits, the r's complement of N is defined as rn - N for N ≠ 0 and 0 for N = 0.

➢ Example:

The 10's complement of (52520)10 is 105 −52520 = 47480.

The 10's complement of (0.3267)10 is 1-0.3267 = 0.6733.

No integer part, so 10n = 100 = 1

➢ The 2's complement of (101100), is (26)10 − (101100)2 = (1000000 − 101100)2 = 010100.

➢ The 2's complement of (0.0110)2 is (1 − 0.0110)2 = 0.1010.

(4)

The (r −1)’s Complement

➢ Given a positive number N in base r with an integer part of n digits and a fraction part of m digits, the (r −1)’s complement of N is defined as rn − r−m − N.

➢ Examples :

The 9's complement of (52520)10 is (105 −1− 52520) = 99999 − 52520 = 47479

The 9's complement of (0.3267)10 is (1−10−4 − 0.3267) = 0.9999 − 0.3267 = 0.6732.

The 9's complement of (25.639)10 is (102 −10−3 −25.639) = 99.999 − 25.639 = 74.360.

➢ The 1's complement of (101100)2 is (26 − 1) − (101100) = (111111 − 101100)2 = 010011 The 1’s complement of (0.0110)2,is (1−2−4)10− (0.0110)2 = (0.1111 − 0.0110)2 = 0.1001

(5)

Subtraction with r’s complement

➢ The subtraction of two positive numbers (M-N ), both of base r, may be done as follow:

1. Add the minuend M to the r's complement of the subtrahend N.

2. Inspect the result obtained in step 1 for an end carry:

(a) If an end carry occurs, discard it.

(b) If an end carry does not occur, take the r's complement of the number obtained in step 1 and place a negative sign in front.

(6)

EXAMPLE: Using 10's complement, subtract 72532 − 3250.

M = 72532 N = 03250

10's complement of N = 96750

answer: 69282

EXAMPLE : Subtract: (3250 −72532)10 M = 03250

N = 72532

10's complement of N = 27468

answer: −69282 = −(10's complement of 30718)

72532 + 96750 69282 end carry →1

03250 +27468 30718 no carry

(7)

EXAMPLE : Use 2’s complement to perform M −N with the given binary numbers.

(a) M = 1010100 N = 1000100 2’s complement of N = 0111100 answer: 10000

(b) M =1000100 N = 1010100

2's complement of N = 0101100

answer: − 10000 = − (2's complement of 1110000)

1010100 + 0111100 0010000 end carry → 1

1000100 + 0101100 1110000 no carry

(8)

Subtraction using (r −1)’s complement

➢ The subtraction of M −N, both positive numbers in base r, may be calculated in the following

manner:

1. Add the minuend M to the (r −1)'s complement of the subtrahend N.

2. Inspect the result obtained in step 1 for an end carry.

(a) If an end carry occurs, add 1 to the least significant digit (end-around carry).

(b) If an end carry does not occur, take the (r −1)'s complement of the number obtained in step 1 and place a negative sign in front.

(9)

EXAMPLE: Using 9's complement, subtract 72532 − 3250.

M = 72532 N = 03250

9's complement of N = 96749

answer: 69282

EXAMPLE : Subtract: (3250 −72532)10 M = 03250

N = 72532

9's complement of N = 27467

answer: −69282 = −(9's complement of 30717)

72532 + 96749 69281 + 1 69282 End-around carry →1

03250 +27467 30717 no carry

(10)

EXAMPLE : Use 1’s complement to perform M −N with the given binary numbers.

(a) M = 1010100 N = 1000100 1’s complement of N = 0111011 answer: 10000

(b) M =1000100 N = 1010100

1's complement of N = 0101011

answer: − 10000 = − (1's complement of 1101111)

1010100 + 0111011 0001111 + 1

0010000 end-around carry → 1

1000100 + 0101011 1101111 no carry

(11)

Signed Numbers

➢ Digital systems, such as the computer, must be able to handle both positive and negative numbers.

➢ A signed binary number consists of both sign and magnitude information.

➢ The most significant bit (MSB) is the sign bit and treating the remaining bits as magnitude bits.

➢ There are three forms in which signed integer number can be represented in binary.

❖ Sign magnitude form

❖ 1’s Complement form

❖ 2’s Complement form

(12)

Sign Magnitude form

➢ Signed-magnitude form

❖ The sign bit is the left-most bit in a signed binary number

❖ A 0 sign bit indicates a positive magnitude

❖ A 1 sign bit indicates a negative magnitude

Example: +25 = 00011001

−25 = 10011001

Sign bit Magnitude bits

(13)

1’s Complement Form

➢ 1’s complement form

❖ A negative number is the 1’s complement of the corresponding positive number.

❖ Positive numbers in 1’s complement form are represented the same way as the positive signed magnitude numbers.

➢ Example: +25 = 00011001

❖ Using 8 bits, decimal number −25 is expressed as the 1’s complement of +25 (00011001) as

−25 = 11100110

(14)

2’s Complement Form

➢ 2’s complement form

❖ A negative number is the 2’s complement of the corresponding positive number.

❖ Positive numbers in 2’s complement form are represented the same way as in the signed magnitude and 1’s complement form.

➢ Example: +25 = 00011001

❖ Using 8 bits, decimal number −25 is expressed as the 2’s complement of +25 (00011001) as

−25 = 11100111

(15)

The Decimal Value of Signed Numbers

➢ Sign-Magnitude

❖ Decimal values of positive and negative numbers in the sign-magnitude form are determined

by summing the weights in all the magnitude bit positions where there are 1s and ignoring those positions where there are zeros.

❖ The sign is determined by examination of the sign bit

(16)

Example:

(17)

➢ 1’s Complement

❖ Decimal values of positive numbers in the 1’s complement form are determined by summing

the weights in all bit positions where there are 1s and ignoring those positions where there are zeros.

❖ Decimal values of negative numbers are determined by assigning a negative value to the weight of the sign bit, summing all the weights where there are 1s, and adding 1 to the result.

(18)

Example:

(19)

➢ 2’s Complement

❖ Decimal values of positive and negative numbers in the 2’s complement form are determined

by summing the weights in all bit positions where there are 1s and ignoring those positions where there are zeros.

❖ The weight of the sign bit in a negative number is given a negative value.

(20)

Example:

(21)

Range of Signed Integer Numbers

➢ 8-bit grouping is common in most computers and has been given the special name byte.

➢ With one byte or eight bits, you can represent 256 different numbers.

➢ With two bytes or sixteen bits, you can represent 65,536 different numbers.

➢ The formula for finding the number of different combinations of n bits is Total combinations = 2n

➢ For signed magnitude and 1’s complement signed numbers, the range of values for n-bit numbers is

Range = −(2n−1 −1) to +(2n−1 − 1) and ± 0

➢ For 2’s complement signed numbers, the range of values for n-bit numbers is Range = −(2n−1) to +(2n−1 − 1)

Note: In each case there is one sign bit and n−1 magnitude bits.

References

Related documents

Corporations such as Coca Cola (through its Replenish Africa Initiative, RAIN, Reckitt Benckiser Group and Procter and Gamble have signalled their willingness to commit

It seems, therefore, important at the outset, before treating the more specific aspects of the topic of this article, to look for the main factors which have l e d

These gains in crop production are unprecedented which is why 5 million small farmers in India in 2008 elected to plant 7.6 million hectares of Bt cotton which

INDEPENDENT MONITORING BOARD | RECOMMENDED ACTION.. Rationale: Repeatedly, in field surveys, from front-line polio workers, and in meeting after meeting, it has become clear that

Section 2 (a) defines, Community Forest Resource means customary common forest land within the traditional or customary boundaries of the village or seasonal use of landscape in

1. The white-collar crimes are committed by people who are financially secure and perform such illegal acts for satisfying their wants. These crimes are generally moved

To break the impasse, the World Bank’s Energy Sector Management Assistance Program (ESMAP), in collaboration with Loughborough University and in consultation with multiple

3.6., which is a Smith Predictor based NCS (SPNCS). The plant model is considered in the minor feedback loop with a virtual time delay to compensate for networked induced