CSCI 220: Computer Architecture-I Instructor: Pranava K. Jha BCD Codes Q. Give representation of the decimal number 853 in each of the following codes. (a) 8421 code (c) 84(-2)(-1) code (b) Excess-three code (d) 753(-6) code. Decimal digit 8421 code Excess-three code 84(-2)(-1) code 753(-6) code 8 1000 1011 1000 0110 5 0101 1000 1011 0100 3 0011 0110 0101 0010 A code for the decimal number 853 is obtainable by carefully juxtaposing the respective four-bit groups for 8, 5 and 3, respectively. Decimal number 8421 code Excess-three code 84(-2)(-1) code 753(-6) code 853 100001010011 101110000110 100010110101 011001000010 Q. Encode the decimal digits 0 through 9 with four bits using 832( 4) code. Is this code self-complementing? Explain. Decimal digit 832( 4) code 0 0 0 0 0 1 0 1 1 1 2 0 0 1 0 3 0 1 0 0 4 1 0 0 1 5 0 1 1 0 6 1 0 1 1 7 1 1 0 1 8 1 0 0 0 9 1 1 1 1 The code is indeed self-complementing. This is because if a decimal digit r receives the code abcd, then the decimal digit 9 r receives the code a b c d, where a = 1 a. 1 of 8
Q. Prove that in a four-bit weighted BCD code with all positive weights, at most one weight can exceed 4. Let w 1, w 2, w 3 and w 4 be the four positive weights in weighted BCD code. Assume by way of contradiction that there are at least two weights that are greater than 4, i.e., a maximum of two weights are between 1 and 4. Without loss of generality, assume that 1 w 1 w 2 4, and w 3, w 4 5. The following table shows that at least one decimal digit cannot be represented in such a code. w 1 w 2 1 1 Cannot represent 3 or 4. 1 2 Cannot represent 4. 1 3 Cannot represent 2. 1 4 Cannot represent 2 or 3. 2 2 Cannot represent 1 or 3. 2 3 Cannot represent 1 or 4. 2 4 Cannot represent 1 or 3. 3 3 Cannot represent 1, 2 or 4. 3 4 Cannot represent 1 or 2. 4 4 Cannot represent 1, 2 or 3. The situation is worse if there is just one weight between 1 and 4. Contradiction! Q. Consider the string 100010010111. What decimal number does it represent if it is viewed as a string in (a) BCD, (b) Excess-three code and (c) 84(-2)(-1) code? Examine 100010010111 as a string of four-bit groups as below. 1000 1001 0111 Now replace each four-bit group by the corresponding decimal digit in the respective code. BCD Excess-three code 84(-2)(-1) code 100010010111 897 564 871 2 of 8
Q. Complete the following table with respect to 7536 BCD code. Decimal digit 7536 code 0 0 0 0 0 1 1 0 0 1 2 0 1 1 1 3 0 0 1 0 4 1 0 1 1 5 0 1 0 0 6 1 1 0 1 7 1 0 0 0 8 0 1 1 0 9 1 1 1 1 7536 code is an example of a self-complementing code. Such a code has the property that the code word for the 9's complement of a digit is obtainable by complementing the individual bits of the digit's code word. Other self-complementing codes include excessthree code and8421code. Self-complementing codes were used in early calculators. Q. A four-input, one-output circuit is to be designed. The inputs are 7536 code groups. The output f is (i) a 1 if the digit D represented is in the range 0 D 3, (ii) a 0 if the digit D is in the range 4 D 9, and (iii) a if the digit D is invalid, i.e., not in the range 0 D 9. Complete the following table for this purpose. 7 5 3 6 w x y z Digit D Output f 0 0 0 0 0 1 0 0 0 1 0 0 1 0 3 1 0 0 1 1 0 1 0 0 5 0 0 1 0 1 0 1 1 0 8 0 0 1 1 1 2 1 1 0 0 0 7 0 1 0 0 1 1 1 1 0 1 0 1 0 1 1 4 0 1 1 0 0 1 1 0 1 6 0 1 1 1 0 1 1 1 1 9 0 3 of 8
Q. Prove that in a self-complementing BCD code, which can have both positive and negative weights, the algebraic sum of all the weights must be 9. A self-complementing BCD code has the property that the four-bit binary string corresponding to a digit d is obtainable from the four-bit binary string corresponding to (9 d) through bit-wise complementation. If a digit d is representable as the four-bit binary string a 3 a 2 a 1 a 0, then the digit (9 d) is representable as (1 a 3 )(1 a 2 ) (1 a 1 ) (1 a 0 ), where 0 d 9 and 0 a i 1. Let w 3, w 2, w 1 and w 0 be the weights of a self-complementing BCD code. Further, let a 3 a 2 a 1 a 0 be the code for the digit 0, whence (1 a 3 )(1 a 2 ) (1 a 1 ) (1 a 0 ) is the code for the digit 9. It is clear that 0 = a 3 w 3 + a 2 w 2 + a 1 w 1 + a 0 w 0. 9 = (1 a 3 )w 3 + (1 a 2 )w 2 + (1 a 1 )w 1 + (1 a 0 )w 0. A simple summation yields: 9 = w 3 + w 2 + w 1 + w 0. QED Q. Encode the decimal digits 0 through 9 with four bits using the following weighted BCD codes. For each code, state whether it is self-complementing or not: (i) 7635 code, (ii) 8324 code. 7635 code 8324 code 0 0000 1 0101 2 1001 3 0010 4 0111 5 1011 6 0100 7 1000 8 1101 9 0110 0 0000 1 0111 2 0010 3 0100 4 1001 5 0110 6 1011 7 1101 8 1000 9 1111 It is clear that 7635 code is not self-complementing while8324 code is. 4 of 8
Q. The following block diagram corresponds to a code converter that takes a four-bit representation of a decimal digit in 84(-2)(-1) code and produces the corresponding fourbit representation in 8421 code. A B C D 8 8 4 4-2 2-1 1 W X Y Z Develop simplified expressions for W, X, Y and Z in terms of A, B, C and D. Make use of don t-care conditions. The following table is immediate. 84(-2)(-1) code Decimal BCD A B C D digit W X Y Z 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 4 0 1 0 0 0 1 0 1 3 0 0 1 1 0 1 1 0 2 0 0 1 0 0 1 1 1 1 0 0 0 1 1 0 0 0 8 1 0 0 0 1 0 0 1 7 0 1 1 1 1 0 1 0 6 0 1 1 0 1 0 1 1 5 0 1 0 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 9 1 0 0 1 Karnaugh maps follow. 5 of 8
K-map for W K-map for X Simplified expressions and a circuit diagram follow. w = AB +AC D. x = B C + B D +BC D. y = C D + CD. z = D. K-map for Y K-map for Z 6 of 8
Q. The following block diagram corresponds to a code converter that takes a four-bit representation of a decimal digit in 8421 code and produces the corresponding four-bit representation in excess-three code. A B C D 8 4 2 1 W W Y Z Present the truth table for this purpose. Make use of don t-care conditions. 8421 code A B C D Decimal digit Excess-three code W X Y Z 0 0 0 0 0 0 0 1 1 0 0 0 1 1 0 1 0 0 0 0 1 0 2 0 1 0 1 0 0 1 1 3 0 1 1 0 0 1 0 0 4 0 1 1 1 0 1 0 1 5 1 0 0 0 0 1 1 0 6 1 0 0 1 0 1 1 1 7 1 0 1 0 1 0 0 0 8 1 0 1 1 1 0 0 1 9 1 1 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 7 of 8
Q. Find the binary representation for each of the following BCD numbers: 0100100001100111 001101111000.01110101 (0100 1000 0110 0111) BCD = (4867) 10 = (1001100000011) 2 (0011 0111 1000.0111 0101) BCD = (378.75) 10 = (101111010.11) 2 Q. Consider the binary string 100010010111. What decimal number does it represent if it is viewed as a string in (a) BCD, (b) Excess-three code and (c) 84(-2)(-1) code? Examine 100010010111 as a string of four-bit groups as below. 1000 1001 0111 Now replace each four-bit group by the corresponding decimal digit in the respective code. Binary string 8421 (BCD) Excess-three code 84(-2)(-1) code 100010010111 897 564 871 o 8 of 8