Decimal numbers greater than 9 or less than 1 can be represented by the NBCD code if each digit is giver in that code and if the results are combined. For example, the number 63.98 is represented by (or converted to)NBCD code as 63 639810=01100011.10011000)BCD 1100011.10011NBCD Here, the code weights are80,40,20,10;8,4,2,1;0.8,0.4,0.2,0.1;and0.08,0.04,0.02,0.01 for the tens units,tenths, and hundredths digits, respectively, representing four decades. Conversion between binary and NBCD requires conversion to decimal as an intermediate step. For example, to convert from NBCD to binary requires that groups of four bits be selected in both directions from the radix point to form the decimal number. If necessary, zeros are added to the leftmost or rightmost ends to complete the groups of four bits as in the above example. Negative NBCD numbers can be represented either in sign-magnitude notation or 1s or 2s complement notation as discussed later Another BCD code that is used for number representation and manipulation is called excess 3 BCD (or XS3 NBCD, or simply XS3) XS3 is an example of a biased-weighted code (a bias of 3). This code is formed by ding 00112(=310)to the NBCD bit patterns in Table 86. 2. Thus, to convert XS3 to NBCD code, 0011 must be subtracted from XS3 code In four-bit quantities the XS3 code has the useful feature that when adding two numbers together in XS3 notation a carry will result and yield the correct value any time a carry results decimal (i.e, when 9 is exceeded). This feature is not shared by either natural binary or NBCD addition The Hexadecimal and Octal Systems The hexadecimal number system requires that r= 16 in Eqs.(86.1)and(86.2), indicating that there are 16 distinguishable characters in the system. By convention, the permissible hexadecimal digits are 0, 1, 2, 3,4,5, 6,7,8,9,A,B, C,D,E, and F for decimals O through 15, respectively. Examples of the positional and polynom representations for a hexadecimal number are h2h2h1h.h1h2h3…h =(AF3C8)16 with a decimal value of N=∑h6 10×162+15×16+3×16+12×16-1+8×16-2 =2803.7812510 Here, it is seen that a hexadecimal number has been converted to decimal by using Eq (86.2 The octal number system requires that r=8 in Eqs. (86.)and(86.2), indicating that there are eight distinguishable characters in this system. The permissible octal digits are 0, 1, 2, 3, 4, 5, 6, and 7, as one might expect. Examples of the application of Eqs.(86. 1)and (86. 2)are 501.74 with a decimal value of e 2000 by CRC Press LLC
© 2000 by CRC Press LLC Decimal numbers greater than 9 or less than 1 can be represented by the NBCD code if each digit is given in that code and if the results are combined. For example, the number 63.98 is represented by (or converted to) NBCD code as 6 3 . 9 8 63.9810 = 0110 0011 . 1001 1000)NBCD = 1100011.10011NBCD Here, the code weights are 80, 40, 20, 10; 8, 4, 2, 1; 0.8, 0.4, 0.2, 0.1; and 0.08, 0.04, 0.02, 0.01 for the tens, units, tenths, and hundredths digits, respectively, representing four decades. Conversion between binary and NBCD requires conversion to decimal as an intermediate step. For example, to convert from NBCD to binary requires that groups of four bits be selected in both directions from the radix point to form the decimal number. If necessary, zeros are added to the leftmost or rightmost ends to complete the groups of four bits as in the above example. Negative NBCD numbers can be represented either in sign-magnitude notation or 1’s or 2’s complement notation as discussed later. Another BCD code that is used for number representation and manipulation is called excess 3 BCD (or XS3 NBCD, or simply XS3). XS3 is an example of a biased-weighted code (a bias of 3). This code is formed by adding 00112 (= 310) to the NBCD bit patterns in Table 86.2. Thus, to convert XS3 to NBCD code, 0011 must be subtracted from XS3 code. In four-bit quantities the XS3 code has the useful feature that when adding two numbers together in XS3 notation a carry will result and yield the correct value any time a carry results in decimal (i.e., when 9 is exceeded). This feature is not shared by either natural binary or NBCD addition. The Hexadecimal and Octal Systems The hexadecimal number system requires that r = 16 in Eqs. (86.1) and (86.2), indicating that there are 16 distinguishable characters in the system. By convention, the permissible hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F for decimals 0 through 15, respectively. Examples of the positional and polynomial representations for a hexadecimal number are N16 = (hn–1 … h3h2h1h0 . h–1h–2h–3 … h–m)16 = (AF3.C8)16 with a decimal value of Here, it is seen that a hexadecimal number has been converted to decimal by using Eq. (86.2). The octal number system requires that r = 8 in Eqs. (86.1) and (86.2), indicating that there are eight distinguishable characters in this system. The permissible octal digits are 0, 1, 2, 3, 4, 5, 6, and 7, as one might expect. Examples of the application of Eqs. (86.1) and (86.2) are N8 = (on–1 … o3o2o1o0 . o–1o–2o–3 … o–m)8 = 501.748 with a decimal value of N hi i i m n = = ¥ + ¥ + ¥ + ¥ + ¥ = = - - - - Â 16 10 16 15 16 3 16 12 16 8 16 2803 78125 1 2 1 0 1 2 10
TABLE 86.3 The BCh and BCO Number Binary BCH BCO Decimal Binary BCH BCO Decimal 1010 1100C 1101D l110 100001020 10 l10001 100 N 08 +0×81+1×8°+7×8-1+4×8 321.937510 When the hexadecimal and octal number systems are used to represent bit patterns in binary, they are called binary-coded hexadecimal(BCH) and binary-coded octal(BCO), respectively. These two number systems are examples of binary-derived radices. Table 86.3 lists several selected examples showing the relationships between BCO, binary, and decimal. What emerges on close inspection of Table 86.3 is that each hexadecimal digit corresponds to four binary digits and that each octal digit corresponds to three binary digits. The following example illustrates the relationships between these number systems: l0110l11ll.110112=010110l11l11.11011000 5BED8 2677 66 01011011 10110 2677.668 1471.8437510 To separate the binary digits into groups of four(for BCH)or groups of three(for BCO), counting must begin from the radix point and continue outward in both directions. Then, where needed, zeros are added to the leading and trailing ends of the binary representation to complete the MSDs and LSDs for the BCH and BCO forms Conversion between Number Systems It is not the intent of this section to cover all methods for radix(base)conversion. Rather, the plan is to provide general approaches, separately applicable to the integer and fraction portions, followed by specific examples Conversion of Integer Since the polynomial form of Eq.(86.2)is a geometrical progression, the integer portion can be represented in nested radix form. In source radix s, the nested representation is e 2000 by CRC Press LLC
© 2000 by CRC Press LLC When the hexadecimal and octal number systems are used to represent bit patterns in binary, they are called binary-coded hexadecimal (BCH) and binary-coded octal (BCO), respectively. These two number systems are examples of binary-derived radices. Table 86.3 lists several selected examples showing the relationships between BCH, BCO, binary, and decimal. What emerges on close inspection of Table 86.3 is that each hexadecimal digit corresponds to four binary digits and that each octal digit corresponds to three binary digits. The following example illustrates the relationships between these number systems: 5 B F . D 8 10110111111.110112 = 0101 1011 1111 . 1101 1000 = 5BF.D816 2 6 7 7 . 6 6 = 010 110 111 111 . 110 110 = 2677.668 = 1471.8437510 To separate the binary digits into groups of four (for BCH) or groups of three (for BCO), counting must begin from the radix point and continue outward in both directions. Then, where needed, zeros are added to the leading and trailing ends of the binary representation to complete the MSDs and LSDs for the BCH and BCO forms. Conversion between Number Systems It is not the intent of this section to cover all methods for radix (base) conversion. Rather, the plan is to provide general approaches, separately applicable to the integer and fraction portions, followed by specific examples. Conversion of Integers Since the polynomial form of Eq. (86.2) is a geometrical progression, the integer portion can be represented in nested radix form. In source radix s, the nested representation is TABLE 86.3 The BCH and BCO Number Systems Binary BCH BCO Decimal Binary BCH BCO Decimal 0000 0 0 0 1010 A 12 10 0001 1 1 1 1011 B 13 11 0010 2 2 2 1100 C 14 12 0011 3 3 3 1101 D 15 13 0100 4 4 4 1110 E 16 14 0101 5 5 5 1111 F 17 15 0110 6 6 6 10000 10 20 16 0111 7 7 7 11011 1B 33 27 1000 8 10 8 110001 31 61 49 1001 9 11 9 1001110 4E 116 78 N oi i i m n = = ¥ + ¥ + ¥ + ¥ + ¥ = = - - - - Â 8 5 8 0 8 1 8 7 8 4 8 321 9375 1 2 1 0 1 2 10
+s(a t s(a for digits a; having integer values from 0 to s-1. The nested radix form not only suggests a conversion proces but also forms the basis for computerized conversion. Consider that the number in Eq. (86.3)is to be represented in nested radix r form N,=b+r(b+r(b2+…+bm-1) (86.4) where, in general, m* n. Then, if N, is divided by r, the results are of the form R =0+ (86.5) where Q is the integer quotient rearranged as Q=b,+rb+-+ bm-I)))), and R is the remainder ro= bo A second division by r yields Q/r=Q+R,/r, where Q is arranged as Q=b2+ r(b,+..+ b-d)), and r= b,. Thus, by repeated division of the integer result Q, by r, the remainders yield(bo, b,, b2,...,bm-1), in that order. The conversion method just described, called the radix divide method, can be used to convert between any two integers of different radices. However, the requirement is that the arithmetic required by N, /r must be carried out in source radix, s. Except for source radices 10 and 2, this poses a severe problem for humans. Table 86.4 provides the recommended procedures for integer conversion. The radix divide method is suitable for computer conversion providing, of course, that the computer is programmed to carry out the arithmetic in different radice TABLE 86.4 Summary of Recommended Methods for Integer Conversion by Noncomputer Means N1n→N Radix division by radix r using Eq. (86.5 863) 10->Nm10N→ NIo by Eq(86.2)or(86.3) 6-N, radix division by r using Eq.(86.5) Special Cases for Binary Forms MMN Partition N, into groups of four bits starting from radix point, then apply Table 86 N, into groups of three bits starting from radix point, then apply Table 86.3 NBco→N2 NBco→ o→N2→N NBCD→Ns Add 0011,(=3,o)to Naacp Nxs- NNHoD Subtract 0011,(=31o) from NNECD e 2000 by CRC Press LLC
© 2000 by CRC Press LLC (86.3) for digits ai having integer values from 0 to s – 1. The nested radix form not only suggests a conversion process but also forms the basis for computerized conversion. Consider that the number in Eq. (86.3) is to be represented in nested radix r form (86.4) where, in general, m ¹ n. Then, if Ns is divided by r, the results are of the form (86.5) where Q is the integer quotient rearranged as Q0 = b1 + r(b2 + … + bm–1 ))))r and R is the remainder R0 = b0. A second division by r yields Q0 /r = Q1 + R1 /r, where Q1 is arranged as Q1 = b2 + r(b3 + … + bm–1)))r and R1 = b1. Thus, by repeated division of the integer result Qi by r, the remainders yield (b0 , b1, b2 , …, bm–1)r in that order. The conversion method just described, called the radix divide method, can be used to convert between any two integers of different radices. However, the requirement is that the arithmetic required by Ns/r must be carried out in source radix, s. Except for source radices 10 and 2, this poses a severe problem for humans. Table 86.4 provides the recommended procedures for integer conversion. The radix divide method is suitable for computer conversion providing, of course, that the computer is programmed to carry out the arithmetic in different radices. TABLE 86.4 Summary of Recommended Methods for Integer Conversion by Noncomputer Means Integer Conversion Conversion Method N10 Æ Nr Radix division by radix r using Eq. (86.5) Ns Æ N10 Eq. (86.2) or Eq. (86.3) Ns )s¹10 —> Nr )r¹10 Ns Æ N10 by Eq. (86.2) or (86.3) N10 Æ Nr radix division by r using Eq. (86.5) Special Cases for Binary Forms N2 Æ N10 Positional weighting N2 Æ NBCH Partition N2 into groups of four bits starting from radix point, then apply Table 86.3 N2 Æ NBCO Partition N2 into groups of three bits starting from radix point, then apply Table 86.3 NBCH Æ N2 Reverse of N2 Æ NBCH NBCO Æ N2 Reverse of N2 Æ NBCO NBCH Æ NBCO NBCH Æ N2 Æ NBCO NBCO Æ NBCH NBCO Æ N2 Æ NBCH NNBCD Æ NXS3 Add 00112 (= 310) to NNBCD NXS3 Æ NNBCD Subtract 00112 (= 310) from NNBCD N a s a s a s a s a s a s a a a s a s s s s n n n n n i i i n = ( + + + + ) = + + + + = + Ê Ë Á ˆ ¯ ˜ - - - - - - = - Â 1 1 2 2 1 1 0 0 012 1 0 1 1 1 L ( ( L ))))) N b r b r b b b r b r r m i i i m r = + + + + = + Ê Ë Á ˆ ¯ ˜ - - = - Â 012 1 0 1 1 1 ( ( L ))))) N r Q R r s = +
The integer conversion methods of Table 86.4 can be illustrated by the following simple examples Example 1.139→N2 R 139/2=691 69/2=341 17/2 20 01139=10001011 Example 2. 100010112- N1o By positional weights, N1o=128+8+2+1=13910 Example3.1391a→N Q R 139/8=173 17/8=21 2/8=0213910=213 Example 4. 100010112 NBco 213 Example5.213g→NBa 13Bo=010001011=100010112=10001011=8B16 Example6.2138→N 2138 N/r Q R 27/5 1/5=012138=10245 Check:1×53+2×51+4×5°=125+10+4=139 Conversion of fractions By extracting the fraction portion from Eq. (86. 2)one can write s(a1+s-(a2+…+an) (86.6) (a- ,+>a s-i+) in radix s. This is called the nested inverse radix form that provides the basis for computerized conversion. e 2000 by CRC Press LLC
© 2000 by CRC Press LLC The integer conversion methods of Table 86.4 can be illustrated by the following simple examples: Example 1. 13910 Æ N2 N/r Q R 139/2 = 69 1 69/2 = 34 1 34/2 = 17 0 17/2 = 8 1 8/2 = 4 0 4/2 = 2 0 2/2 = 1 0 1/2 = 0 1 13910 = 100010112 Example 2. 100010112 Æ N10. By positional weights, N10 = 128 + 8 + 2 + 1 = 13910 Example 3. 13910 Æ N8 N/r QR 139/8 = 17 3 17/8 = 2 1 2/8 = 0 2 13910 = 2138 Example 4. 100010112 Æ NBCO 213 010 001 011 = 213BCO Example 5. 213BCO Æ NBCH 213 8 B 213BCO = 010 001 011 = 100010112 = 1000 1011 = 8B16 Example 6. 2138 Æ N5 2138 = 2 ¥ 82 + 1 ¥ 81 + 3 ¥ 80 = 13910 N/r Q R 139/5 = 27 4 27/5 = 5 2 5/5 = 1 0 1/5 = 0 1 2138 = 10245 Check: 1 ¥ 53 + 2 ¥ 51 + 4 ¥ 50 = 125 + 10 + 4 = 13910 Conversion of Fractions By extracting the fraction portion from Eq. (86.2) one can write (86.6) in radix s. This is called the nested inverse radix form that provides the basis for computerized conversion. .( ) ( ( ))))) ( ) N as as a s sa sa a s a as s m m s m s i i s i m = + ++ = + ++ = + - - - - - - - - - - - - - - - + = Â 1 1 2 2 1 1 1 2 1 1 1 2 L L
ABLE 86.5 ry of Recommended Methods for fraction c n by Noncomputer Means Fraction Conversion Method Radix multiplication by using Eq(86.8) quation(86.2) A,m→)mNm山b(68 Special Cases for Binary Forms N2→,NB Partition. N2 into groups of four bits from radix point, then apply Table 86.3 Partition N2 into groups of three bits from radix point, then apply Table 86.3 NaH→.N2 Reverse of.N2→.NB NB→.N2 Reverse of.N2→.NB NBa→. NuCO . NECH→N2→NBco NB→NBc If the fraction in Eq (86.6) is represented in nested inverse radix r form, then "(6 +b-P)) (86.7) (b+∑br“) for any fraction represented in radix r. Now, if N, is multiplied by r, the result is of the for N.×r=I+F (86.8) where I is the product integer, I,= b-I, and Fo is the product fraction arranged as F=r(b-2+r(b-3+.+ b)))),. By repeated multiplication by r of the remaining fractions F, the resulting integers yield(b-,b-2 b33…bn), in that order The conversion just described is called the radix multiply method and is perfectly general for converting between fractions of different radices. However, as in the case of integer conversion, the requirement is that the arithmetic required by N, Xr must be carried out in source radix, s For noncomputer use by humans, this procedure is usually limited to fraction conversions N1o -N, where the source radix is 10( decimal). The recommended methods for converting between fractions of different radices are given in Table 86.5. The radix multiply method is well suited to computer use. 4 For any integer of radix s, there exists an exact representation in radix r. This is not the case for a fraction lose conversion is a geometrical progression that never converges. Terminating a fraction conversion at digits(to the right of the radix point)results in an error or uncertainty. In decimal, this error is given by r+ a n+]) ∑ where the quantity in brackets approaches the value of a_+ 1. Therefore, terminating a fraction conversion at n digits from the radix point results in an error with bounds e 2000 by CRC Press LLC
© 2000 by CRC Press LLC If the fraction in Eq. (86.6) is represented in nested inverse radix r form, then (86.7) for any fraction represented in radix r. Now, if Ns is multiplied by r, the result is of the form .Ns ¥ r = I + F (86.8) where I is the product integer, I1 = b–1, and F0 is the product fraction arranged as F1 = r –1(b–2 + r –1(b–3 + … + b–p))))r . By repeated multiplication by r of the remaining fractions Fi , the resulting integers yield (b–1, b–2 , b–3 , … b–m)r , in that order. The conversion just described is called the radix multiply method and is perfectly general for converting between fractions of different radices. However, as in the case of integer conversion, the requirement is that the arithmetic required by .Ns ¥ r must be carried out in source radix, s. For noncomputer use by humans, this procedure is usually limited to fraction conversions N10 Æ Nr , where the source radix is 10 (decimal). The recommended methods for converting between fractions of different radices are given in Table 86.5. The radix multiply method is well suited to computer use. For any integer of radix s, there exists an exact representation in radix r. This is not the case for a fraction whose conversion is a geometrical progression that never converges. Terminating a fraction conversion at n digits (to the right of the radix point) results in an error or uncertainty. In decimal, this error is given by where the quantity in brackets approaches the value of a–n + 1. Therefore, terminating a fraction conversion at n digits from the radix point results in an error with bounds TABLE 86.5 Summary of Recommended Methods for Fraction Conversion by Noncomputer Means Fraction Conversion Conversion Method .N10 Æ .Nr Radix multiplication by using Eq. (86.8) .Ns Æ .N10 Equation (86.2) or Eq. (86.6) .Nr )s¹10 Æ .Nr )r¹10 Ns Æ Ns10 by Eq. (86.2) or Eq. (86.6) N10 Æ Nr radix multiply by Eq. (86.8) Special Cases for Binary Forms .N2 Æ .NBCH Partition .N2 into groups of four bits from radix point, then apply Table 86.3 .N2 Æ .NBCO Partition .N2 into groups of three bits from radix point, then apply Table 86.3 .NBCH Æ .N2 Reverse of .N2 Æ .NBCH .NBCO Æ .N2 Reverse of .N2 Æ .NBCO .NBCH Æ .NBCO .NBCH Æ .N2 Æ .NBCO .NBCO Æ .NBCH .NBCO Æ .N2 Æ .NBCH . ( ( ))))) ( ) N r b r b b r b b r r p r i i r i p = + + + = + - - - - - - - - - + = Â 1 1 1 2 1 1 1 2 L e10 1 1 2 2 1 = + + + = + È Î Í Í ˘ ˚ ˙ ˙ - - -( ) + -( ) + -( ) + -( ) + - - -( ) + -( ) + = • Â a r a r a r r a a r n n n n n n n n n i n i i r L