0< a in decimal. Equation(86.9)is useful in deciding when to terminate a fraction conversion Often, it is desirable to terminate a fraction conversion at(n+ 1) digits and then round off to n from the radix point. A suitable method for rounding to n digits in radix r is: Perform the fraction conversion to(n+ 1) digits from the radix point, then drop the(n+ 1)digit if a__(m+)<r/2, or add r(m-l) to the result if a-(m+ r/2 After rounding off to n digits, the maximum error becomes the difference between the rounded result and the smallest value possible. By using Eq (86.9), this difference is Then, by rounding to n digits, there results an error with bounds 0<∈10≤r(1-a_m+)/r) (86.10) in decimal If a-(m+n)< r/2 and the(n+ 1)digit is dropped, the maximum error is r". Note that for N,- N1o N, type conversions, the bounds of errors aggregate. The following examples illustrate the fraction conversion methods of Table 86.5 Example 7. 0.- N2 rounded to eight bits 0.654×20.3081 0.308×20.6160 0.232×20.4640 0.464×20.9280 0.928×20.85610.65410=0.101001112 0.856×20.7121 0.424×20.8480∈mx=23 Example 8. 0.65410- Ns terminated at four digits Nxr F 0.654×80.2325 0.232×80.8561 0.856x8 0.848 6 with error bounds Example 9. 0.5166s-N2 rounded to eight bits and let 0.5166s- Nro be rounded to four decimal places 0.51668=5×8-1+1×8-2+6×8-3+6×8-4 0.625000+0.015625+0.011718+0.001465 0. 6538 rounded to four decimal places; E10 s10- F 6538×20.30761 0.3076×20.61520 0.6152×20.2 1 0.2304×20.46080 0.4608×20.92160 e 2000 by CRC Press LLC
© 2000 by CRC Press LLC 0 < e10 £ r –n(a –n + 1) (86.9) in decimal. Equation (86.9) is useful in deciding when to terminate a fraction conversion. Often, it is desirable to terminate a fraction conversion at (n + 1) digits and then round off to n from the radix point. A suitable method for rounding to n digits in radix r is: Perform the fraction conversion to (n + 1) digits from the radix point, then drop the (n + 1) digit if a– (n+1) < r/2, or add r – (n–1) to the result if a– (n+1) ³ r/2. After rounding off to n digits, the maximum error becomes the difference between the rounded result and the smallest value possible. By using Eq. (86.9), this difference is emax = r –n(a –n + 1) – r –n(a – n + a –(n+1)/r) = r –n(1 – a–(n+1)/r) Then, by rounding to n digits, there results an error with bounds 0 < e10 £ r –n(1 – a –(n+1)/r) (86.10) in decimal. If a–(n+1) < r/2 and the (n + 1) digit is dropped, the maximum error is r –n. Note that for Ns Æ N10 Æ Nr type conversions, the bounds of errors aggregate. The following examples illustrate the fraction conversion methods of Table 86.5. Example 7. 0.65410 Æ N2 rounded to eight bits .Ns ¥ r FI 0.654 ¥ 2 0.308 1 0.308 ¥ 2 0.616 0 0.616 ¥ 2 0.232 1 0.232 ¥ 2 0.464 0 0.464 ¥ 2 0.928 0 0.928 ¥ 2 0.856 1 0.65410 = 0.101001112 0.856 ¥ 2 0.712 1 0.712 ¥ 2 0.424 1 0.424 ¥ 2 0.848 0 emax = 2–8 Example 8. 0.65410 Æ N8 terminated at four digits .Ns ¥ r FI 0.654 ¥ 8 0.232 5 0.232 ¥ 8 0.856 1 0.65410 = 51668 0.856 ¥ 8 0.848 6 with error bounds 0.848 ¥ 8 0.784 6 0 < e10 £ 7 ¥ 8–4 = 1.71 ¥ 10–3 Example 9. 0.51668 Æ N2 rounded to eight bits and let 0.51668 Æ N10 be rounded to four decimal places. 0.51668 = 5 ¥ 8–1 + 1 ¥ 8–2 + 6 ¥ 8–3 + 6 ¥ 8–4 = 0.625000 + 0.015625 + 0.011718 + 0.001465 = 0.6538 rounded to four decimal places; e10 £ 10–4 .Ns ¥ r FI 0.6538 ¥ 2 0.3076 1 0.3076 ¥ 2 0.6152 0 0.6152 ¥ 2 0.2304 1 0.2304 ¥ 2 0.4608 0 0.4608 ¥ 2 0.9216 0
0.9216×20.84321 08432×20.686410.5166=0.10100111( ompare with Example7) 0.6864×20.37281 0.3728×20.7457 ∈10≤10-4+2-8=0.0040 Example 10. 0.101001112) NBCH A 0.101001112=0.10100111=0.A7BCH Signed Binary Numbers To this point only unsigned numbers(assumed to be positive)have been considered. However, both positive and negative numbers must be used in computers. Several schemes have been devised for dealing with negative Signed-magnitude representation Radix complement representation Diminished radix complement representation Of these, the radix 2 complement representation, called 2s complement, is the most widely used system in Signed-Magnitude Representation A signed-magnitude number consists of a magnitude together with a symbol indicating its sign(positive or radix r A fraction portion, if present, would consist of m digits to the right of the radix pone teger digits in negative). Such a number lies in the decimal range of -(r-1)through +(rm-l-1)for n int The most common examples of signed-magnitude numbers are those in the decimal and binary systems. The sign symbols for decimal ( or-) are well known. In binary it is established practice to use 0= plus and 1=minus for the sign symbols and to place one of them in the MSB position for each number. Examples in eight-bit binary a +45.50=0101101.12+010=000000002 Magnitude 12310=111110112-010=10000000 Sign bit 个 Although the sign-magnitude system is used in computers, it has two drawbacks. There is no unique zero, s indicated by the examples, and addition and subtraction calculations require time-consuming decisions regarding operation and sign as, for example, (-7)minus(-4). Even so, the sign-magnitude representation is ommonly used in floating-point number systems Radix Complement Representation The radix complement of an n-digit number N, is obtained by subtracting it from r", that is r"-N,.The operation r-N, is equivalent to complementing the number and adding 1 to the LSD. Thus, the radix complement is N,+ lisp where N N, is the complement of a number in radix r. Therefore, one may e 2000 by CRC Press LLC
© 2000 by CRC Press LLC 0.9216 ¥ 2 0.8432 1 0.8432 ¥ 2 0.6864 1 0.51668 = 0.101001112(compare with Example 7) 0.6864 ¥ 2 0.3728 1 0.3728 ¥ 2 0.7457 0 e10 £ 10–4 + 2–8 = 0.0040 Example 10. 0.101001112 Æ NBCH A · 7 0.101001112 = 0.1010 0111 = 0.A7BCH Signed Binary Numbers To this point only unsigned numbers (assumed to be positive) have been considered. However, both positive and negative numbers must be used in computers. Several schemes have been devised for dealing with negative numbers in computers, but only four are commonly used: • Signed-magnitude representation • Radix complement representation • Diminished radix complement representation • Excess (offset) code representation Of these, the radix 2 complement representation, called 2’s complement, is the most widely used system in computers. Signed-Magnitude Representation A signed-magnitude number consists of a magnitude together with a symbol indicating its sign (positive or negative). Such a number lies in the decimal range of –(r n–1 – 1) through +(r n–1 – 1) for n integer digits in radix r. A fraction portion, if present, would consist of m digits to the right of the radix point. The most common examples of signed-magnitude numbers are those in the decimal and binary systems. The sign symbols for decimal (+ or –) are well known. In binary it is established practice to use 0 = plus and 1 = minus for the sign symbols and to place one of them in the MSB position for each number. Examples in eight-bit binary are Magnitude +45.510 = 0 101101.12 +010 = 0 00000002 Sign bit Magnitude –12310 = 1 11110112 –010 = 1 00000002 Sign bit Although the sign-magnitude system is used in computers, it has two drawbacks. There is no unique zero, as indicated by the examples, and addition and subtraction calculations require time-consuming decisions regarding operation and sign as, for example, (–7) minus (–4). Even so, the sign-magnitude representation is commonly used in floating-point number systems. Radix Complement Representation The radix complement of an n-digit number Nr is obtained by subtracting it from r n, that is r n – Nr . The operation r n – Nr is equivalent to complementing the number and adding 1 to the LSD. Thus, the radix complement is Nr+ 1LSD where Nr = r n – 1 – Nr is the complement of a number in radix r. Therefore, one may write
Radix complement of N,=r-N N The complements N, for digits in three commonly used number systems are given in Table 86.6. Notice that the complement of a binary number is formed simply by replacing the 1's with O's and O's with Is as required With reference to Table 86.6 and Eq (86.11), the following examples of radix complement representation Example 11. The 10s complement of 47.83 is Example 12. The 2s complement of 0101101 101 is +11sB=1010010.011 Example 13. The 16s complement of A3D is 6+11sD=5C2+1=5C3 The decimal value of Eq (86. 11)can be found from the polynomial expressio radix cor (86.12) for any n-digit number of radix r. In Eqs. (86.11)and(86.12)the MSD is taken to be the position of the sign 2s Complement Representation. The radix complement for binary is the 2's complement representation. In 2s complement the MSB is the sign bit, I indicating a negative number or 0 if positive. The decimal range of representation for n-integer bits in 2's complement is from -(2 -)through +( -). From Eq(86.11), the 2s complement is formed by N2)2's compl= 2"-N2=N2+1 (86.13) Application of Eq (86. 12)gives the decimal value of any 2s complement number, including those containing a radix point. For example, the pattern N2' compL 11010010.011 has a decimal value N2comp)10=-1×27+1×2+1×2+1×2+1×2+1×23 128+64+16+2+0.25+0.125 -45.62510 The same result could have easily been obtained by first applying Eq.(86. 13)to N2 somn followed by the use of positional weighting to obtain the decimal value. Thus, e 2000 by CRC Press LLC
© 2000 by CRC Press LLC Radix complement of Nr = r n – Nr = Nr + 1 (86.11) The complements Nr for digits in three commonly used number systems are given in Table 86.6. Notice that the complement of a binary number is formed simply by replacing the 1’s with 0’s and 0’s with 1’s as required by 2n – 1 – N2. With reference to Table 86.6 and Eq. (86.11), the following examples of radix complement representation are offered. Example 11. The 10’s complement of 47.83 is N10 + 1LSD = 52.17 Example 12. The 2’s complement of 0101101.101 is N2 + 1LSB = 1010010.011 Example 13. The 16’s complement of A3D is N16 + 1LSD = 5C2 + 1 = 5C3 The decimal value of Eq. (86.11) can be found from the polynomial expression (86.12) for any n-digit number of radix r. In Eqs. (86.11) and (86.12) the MSD is taken to be the position of the sign symbol. 2’s Complement Representation. The radix complement for binary is the 2’s complement representation. In 2’s complement the MSB is the sign bit, 1 indicating a negative number or 0 if positive. The decimal range of representation for n-integer bits in 2’s complement is from –(2n–1) through +(2n–1). From Eq. (86.11), the 2’s complement is formed by N2)2’s compl. = 2n – N2 = N2 + 1 (86.13) A few examples in eight-bit binary are shown in Table 86.7. Notice that application of Eq. (86.13) changes the sign of the decimal value of a binary number (+ to –, and vice versa) and that only one zero representation exists. Application of Eq. (86.12) gives the decimal value of any 2’s complement number, including those containing a radix point. For example, the pattern N2’s compl. = 11010010.011 has a decimal value N2’s compl.)10 = –1 ¥ 27 + 1 ¥ 26 + 1 ¥ 24 + 1 ¥ 21 + 1 ¥ 2–2 + 1 ¥ 2–3 = –128 + 64 + 16 + 2 + 0.25 + 0.125 = –45.62510 The same result could have easily been obtained by first applying Eq. (86.13) to N2’s compl. followed by the use of positional weighting to obtain the decimal value. Thus, N a r a r n n i i i m n radix compl.) ( ) 10 1 1 2 = - - + - = - - Â
TABLE 86.6 Complements for Three TABLE 86.7 Examples of Eight-Bit 2s Commonly Used Number Systems Complement Representations(MSB Sign Bit Digit Binary Decimal Hexadecimal value Compleme 10000001 0123456789AB l1l00001 l1100000 FEDCBA9876543210 11110000 11101111 l1110001 l1110000 l1l1101 l111100 000000l1 00010000 000lll11 001111 +127 01111111 E N2s compl=00101101.101 32+8+5+0.5+0.125 =45.62510 which is known to be a negative number,-45625 10- Negative NBCD numbers can be represented in 2s complement The foregoing discussion on 2's complement applies to NBCD with consideration of how NBCD is formed from binary. As an example, -59.2410 is represented 01011001.00100100)NBcD=10100110.1101110)2 s compl. NBCD In a similar fashion, negative NBCD numbers can also be represented in 1's complement following the procedure given in the next paragraph Sign-magnitude representation of a negative NBCD number simply requires the addition of a sign bit to the NBCD magnitude Diminished Radix Complement Representation The diminished radix complement of a number is obtained by (86.14) N Thus, the complement of a number is its diminished radix complement. It also follows that the radix comple ment of a number is the diminished radix complement with 1 added to the lsd as in Eq (86. 13). The range of representable numbers is-(rl-1)through +(r-l-1)for radix In the binary and decimal number systems, the diminished radix complement representations are the I's mplement and 9s complement, respectively. Examples of 1s complement are shown in Table 86.7 for comparison with those of 2s complement. Notice that in I's complement there are two representations for zero, one for +O and the other for -0. This fact limits the usefulness of the 1s complement representation for omputer arithmetic e 2000 by CRC Press LLC
© 2000 by CRC Press LLC N2’s compl. = 00101101.101 = 32 + 8 + 5 + 0.5 + 0.125 = 45.62510 which is known to be a negative number, –45.62510. Negative NBCD numbers can be represented in 2’s complement. The foregoing discussion on 2’s complement applies to NBCD with consideration of how NBCD is formed from binary. As an example, –59.2410 is represented by 0101 1001.0010 0100)NBCD = 10100110.11011100)2’s compl. NBCD In a similar fashion, negative NBCD numbers can also be represented in 1’s complement following the procedure given in the next paragraph. Sign-magnitude representation of a negative NBCD number simply requires the addition of a sign bit to the NBCD magnitude. Diminished Radix Complement Representation The diminished radix complement of a number is obtained by Nr)dim. rad. compl. = r n – Nr – 1 (86.14) = Nr Thus, the complement of a number is its diminished radix complement. It also follows that the radix complement of a number is the diminished radix complement with 1 added to the LSD as in Eq. (86.13). The range of representable numbers is –(r n–1 – 1) through +(r n–1 – 1) for radix r. In the binary and decimal number systems, the diminished radix complement representations are the 1’s complement and 9’s complement, respectively. Examples of 1’s complement are shown in Table 86.7 for comparison with those of 2’s complement. Notice that in 1’s complement there are two representations for zero, one for +0 and the other for –0. This fact limits the usefulness of the 1’s complement representation for computer arithmetic. TABLE 86.6 Complements for Three Commonly Used Number Systems TABLE 86.7 Examples of Eight-Bit 2’s and 1’s Complement Representations (MSB = Sign Bit) Complement (–Nr ) Decimal 2’s 1’s Digit Binary Decimal Hexadecimal Value Complement Complement 0 1 9 F –128 10000000 1 0 8 E –127 10000001 10000000 2 7 D –31 11100001 11100000 3 6 C –16 11110000 11101111 4 5 B –15 11110001 11110000 5 4 A –3 11111101 11111100 6 3 9 –0 00000000 11111111 7 2 8 +0 00000000 00000000 8 1 7 +3 00000011 00000011 9 0 6 +15 00001111 00001111 A 5 +16 00010000 00010000 B 4 +31 00011111 00011111 C 3 +127 01111111 01111111 D 2 +128 E 1 F 0