• Aucun résultat trouvé

SIGNED BINARY NUMBERS 45

Dans le document Digital Engineering (Page 74-78)

Number Systems, Binary Arithmetic, and Codes

2.6 SIGNED BINARY NUMBERS 45

EXAMPLE 2.14

-010 = 1 000000025:11

Although the sign-magnitude system is used in computers, it has two drawbacks. There is no unique zero, as indicated by the previous examples, and addition and subtraction calculations require time-consuming decisions regarding operation and sign, for example, (-7) minus (-4). Even so, the sign-magnitude representation is connnonly used injloating-point number systems as discussed in Section 2.8.

2.6.2 Radix Complement Representation

The radix complement N re of an n-digit number Nr is obtained by subtracting Nr from rn,

that is,

Nre

=

rl1 Nr

= N

r

+

llSD (2.12)

where

N

r Digit complementation in radix r

This operation is equivalent to that of replacing each digit ai in Nr by (r - 1) - ai and adding 1 to the LSD of the result as indicated by Algorithm 2.5. The digit complements

N

r for three commonly used number systems are given in Table 2.6. Notice that the digit complement of a binary is formed simply by replacing the 1 's with O's and O's with l's required by 211 N2 1

N

2 as discussed in Subsection 2.6.3. The range of representable numbers is -(r"-I) through +(rn -1 - 1).

Application of Eq. (2.12) or Algorithm 2.5 to the binary and decimal number systems requires that for 2'5 complement representation N1C =

N

2

+

lLsB and for 1O's complement NlOc

= N

10

+

lL.5O, where

N

2 and

N

10 are the binary and decimal digit complements given in Table 2.6.

Table 2.6 Digit complements for three commonly used number systems

Complement (N r)

Digit Binary Decimal Hexadecimal

0 9 F

0 8 E

2 7 D

3 6 C

4 5 B

5 4 A

6 3 9

7 2 8

8 I 7

46 CHAPTER 2/ NUMBER SYSTEMS, BINARY ARITHMETIC. AND CODES

Algorithm 2.5: NrC ... N,

Replace each digit (I, in N, by (r - 1) - (I, and then add 1 to the LSD of the rcsuhalll.

A simpler, "pencil-and-paper" method exists for the 2's complement of a number Nz

and is expressed by Algorithm 2.6:

Algorithm 2.6: N2C +- Nl

For any binary number N~ :lIld beginning with the LSB. proceed (Owued the MSB until the firsT 1 bit has been reached. Relain that I bit nnd complement the remainder of the bils toward and including the MSB.

With reference to Table 2.6, Eq. (2.12). and Algorithm 2.5 or 2.6, the following examples of radix complement representation are provided:

EXAMPLE 2.IS The lO's complement of 47.83 is N 10

+

I LSD = 52.17.

Ex.OfPLE 2.16 The2's complement of 0101 101.101 is

Nl +

IU8 = 1010010.011.

EXAMPLE 2.17 The 16's complement of A3D is

N

16

+

IUD == 5C2

+

I = :5C3.

The decimal value of Eq. (2. [2) can be found from the polynomial expression as

.. -2 Nre)IO = -(0 .. _1,,,-1)+

L

o/r'

, . . -III

(2.13)

for any II-digit number of radix r. In Eqs. (2.12) and (2.13) the MSD i)\ talen to be the position of the sign symbol.

2'5 Complement Representation lbe radix complement for binary is the 2's comple-ment (2C) representation. In 2's complement the MSB is the sign bit. I indicating a negative number and 0 a positive ODe. The decimal range of representation for" integer bits in 2's complement is from _(2,,-I) through +(2,,-1 - I). From Eq. (2.12), the 2's complement is formed by

(2.14)

for any binary number Nz of n integer bits. Or by Algorithm 2.5. the 2's complement or a binary number N2 is obtained by replacing each bit (I, in Nz by (I - a,) and adding 1 to me LSB of the result. The simpler pencil-and· paper method. often used to gener.lle 2's complement from a binary number N,. results from application of Algorithm 2.6. III this case

Nl

is the bit complement of tile number as given in Table 2.6. A few examples of 8-bit 2's complement numbers are shown in Table 2.7. Notice that application of Eq. (2.14) or Algorithm 2.6 changes the sign of the dedm31 value of a binary number (+ 10 - and vice versa), and that only one zero representation ex.ists.

Application of Eq. (2.13) gives the decimal value of any 2's complement number. in-cluding those containing a radix point. For example, the p3Uem N2C. = 11010010.011 has

2.6 SIGNED BINARY NUMBERS

Table 2.7 Examples of eight-bit 2's and l's complement representations (MSB = sign bit)

Decimal 2's 1 's

Value Complement Complement

-128 10000000

-127 10000001 10000000

-31 11100001 11100000

-16 11110000 11101111

-15 11110001 11110000

-3 11111101 11111100

-0 00000000 11111111

+0 00000000 00000000

+3 000000 1 I 00000011

+15 00001111 00001111

+16 00010000 00010000

+31 00011111 00011111

+127 01111111 01111111

+128

a decimal value of

(N2c) 10

=

-1 X 27

+

1 X 26

+

1 X 24

+

1 X 2'

+

1 X 2-2

+

1 x r 3

=

-128

+

64

+

16

+

2

+

0.25

+

0.125

= -45.625/0.

47

But the same result could have easily been obtained by negation of N2C followed by the use of positional weighting to obtain the decimal value. Negation is the reapplication of Eq. (2.12) or Algorithms 2.5 or 2.6 to any 2's complement number N2C to obtain its true value. Thus, from the forgoing example the negation of N2C is given by

N2Chc

=

00101101.101

= 32

+

8

+

5

+

0.5

+

0.125

=

45.625/0, which is known to be a negative number, -45.625/0.

Negative BCD numbers are commonly represented in lO's complement notation with consideration of how BCD is formed from binary. As an example, -59.24/0

=

40.76/0 is represented in BCD lO's complement (BCD,IOC) by

-0101 100l.0010 0100)Bcn = 0100 0000.0111 011O)BcD,lOC,

where application of Eq. (2.l2), or Algorithm 2.5 or 2.6, has been applied in radix 10 fol-lowed by the BCD representation as in Subsections 2.4.1. Alternatively, the sign-magnitude (SM) representation of a negative BCD number simply requires the addition of a sign bit

48 CHAPTER 2/ NUMBER SYSTEMS, BINARY ARITHMETIC. AND CODES

10 the BCD magnitude according to Eq. (2.11). Thus,

-0101 1001.0010 OJOO)8CD = (I 01011001.0010 OIOO)YCD.:>SM.

2.6.3 Diminished Radix Complement Representation

The dimini.~hed radix complement N(T_IIC of a number NT having n digits is obtained by (2.15) where. according to Eq. (2.12), N(r-I)C

+

I = Nr<:. Therefore. it follows that

This means the diminished radix complement of a number is lhe digits complemem of thai number as expressed by Algorithm 2.7. The range of representable n digit numbers in diminished radix complement is -(r"-I - I) through +(rn-1 ~ I) for radix r.

Algorithm 2.7: Ntr-I}C ~ Nr

(1) Replace each digit I'l/ of NT by r - 1 - Gi or (2) Complement each digit by

N

r as in Table 2.6.

In the binary and decimal number systems the diminished radix complement represen-tations are the I 's complement and 9's complement, respectively. Thus, I 's complement is the binary digits complement given by N1c = N2, while the 9's complement is the decimal digits complement expressed as N9C =

N

10. Examples of eight-bit t's complements are

shown in Table 2.7 together with their corresponding 2's complement representation for comparison. Nolice that in 1 's complement there are two representations for zero, one for +0 and me other for -0. This fact limits the usefulness of the I 's complement representation for computer arithmetic.

Shown in Table 2.8 are examples of lO's and 9's complement representations in n digits numbering from 3 to 8. Notice that leading D's are added to the number on the left to meet the n digit requirement.

Table 2,8 Examples of 10'5 and 9'5 complement representation

Number

"

10'5 Complement 9's Complement

0

,

[I J()(J(XX) 99999

3 3 997 996

14.59 6 9985.41 9985.40

225 4 9775 9774

21.456 5 78.544 78.543

1827 8 99998173 99998172

4300.50 7 95699.50 95699.49

69.100 6 930.900 930.899

Dans le document Digital Engineering (Page 74-78)