Number Systems, Codes and Complements - Detailed Solutions (Questions 1-72)
Prepared: Detailed step-by-step solutions for all questions (user requested original numbering and full
details)
-----------------------------------------------------------------
1. Characteristics of 2's-complement numbers:
- MSB is sign bit (0 positive, 1 negative).
- For n-bit word, range is -2^(n-1) .. 2^(n-1)-1.
- Negation: invert bits (1's comp) and add 1.
- Single zero; arithmetic uses standard binary adder.
2. Using 10's-complement, subtract:
a) 72532 - 3250: compute directly: 72532 - 3250 = 69282.
Step-by-step (10's-complement method):
- Choose width = number of digits of larger number = 5 (72532 has 5 digits).
- 3250 as 5-digit = 03250. 10's complement of 03250: 99999 - 03250 + 1 = 96750.
- Add: 72532 + 96750 = 169282. Since there is an end carry (1), drop carry -> 69282 (positive).
b) 3250 - 72532:
- Use width 5: 72532 as 5-digit. 10's complement of 72532 = 99999 - 72532 +1 = 27468.
- Add: 03250 + 27468 = 30718. No end carry -> negative result; take 10's complement: 99999 - 30718 +1 =
69282, sign negative -> -69282.
3. 1's and 2's complements for given binary numbers (use given bit width):
- 1010101: 1's = 0101010, 2's = 0101011
- 0111000: 1's = 1000111, 2's = 1001000
- 0000001: 1's = 1111110, 2's = 1111111
- 10000: 1's = 01111, 2's = 10000
- 00000: 1's = 11111, 2's = 00000
4. Binary addition and subtraction (interpret as unsigned unless stated):
a) 110110 (decimal 54) + 11101 (decimal 29) = 1010011 (decimal 83)
110110 - 11101 = decimal 25 -> binary = 11001
a) 100100 (decimal 36) + 10110 (decimal 22) = 111010 (decimal 58)
100100 - 10110 = decimal 14 -> binary = 1110
a) 1101001 (decimal 105) + 11011 (decimal 27) = 10000100 (decimal 132)
1101001 - 11011 = decimal 78 -> binary = 1001110
5. Convert ([Link])_16 to octal: ([Link])_16 = (177.532)_8
6. Convert the following:
a) (23456)_8 -> decimal 10030 -> hex = (272E)_16
b) (5796)_10 -> octal = (13244)_8
c) (AFD6)_16 -> decimal 45014 -> octal = (127726)_8
d) (ADEB)_16 -> decimal = (44523)_10
7. Gray code and conversion (Gray -> Binary):
- Gray code (reflected) changes only 1 bit between consecutive numbers.
- Conversion algorithm (if Gray bits = g_n..g_0, binary b_n..b_0): b_n = g_n; b_{k} = b_{k+1} XOR g_k.
Example: Gray 1101 -> binary: 1001 (steps: b3=1; b2=1 xor 1=0; b1=0 xor 0=0; b0=0 xor 1=1).
8. Distinguish Weighted vs Non-weighted codes:
- Weighted codes: each bit has fixed numeric weight. Example: 8421 BCD (weights 8,4,2,1).
- Non-weighted codes: no positional weight; mapping defines digit values. Example: Gray code, Excess-3.
9. Convert the following:
a) (343)_5 = decimal 98 -> in base 6 = (242)_6
b) (7654)_8 = decimal (4012)_10
c) (634)_8 = decimal 412 -> hex = (19C)_16
10. Subtract (111001)_2 from (101011)_2 using 1's and 2's complement:
- a = 101011 (decimal 43), b = 111001 (decimal 57) -> a - b = -14 (decimal).
- 1's-complement of b (width 6) = 000110. Add to a: 101011 + 000110 = 0110001 (binary).
- 2's-complement of b = 000111. Add to a: 101011 + 000111 = 0110010 (binary).
Result (decimal) = -14; two's-complement representation (6-bit) = '110010'.
11. Difference between 1's and 2's complement:
- 1's complement: invert bits; has +0 and -0; use end-around carry on addition.
- 2's complement: invert bits and add 1; single zero; easier addition/subtraction.
12. Subtract the following using 2's and 1's complement (decimal results shown):
5250 - 321 = 4929
753 - 864 = -111
3570 - 2100 = 1470
20 - 1000 = -980
(If you want digit-by-digit complement working with fixed widths, specify width.)
13. 3-bit Gray code sequence (0 to 7):
0: 000
1: 001
2: 011
3: 010
4: 110
5: 111
6: 101
7: 100
14. First 20 numbers in radix-5 (decimal 0..19):
0, 1, 2, 3, 4, 10, 11, 12, 13, 14, 20, 21, 22, 23, 24, 30, 31, 32, 33, 34
15. 1's & 2's complement of binaries (same as Q3).
9's and 10's complement for decimal numbers (5-digit width assumed): 09900,10000,00000:
- 09900: 9's = 90099, 10's = 90100
- 10000: 9's = 89999, 10's = 90000
- 00000: 9's = 99999, 10's = 100000
16. Convert decimal 46 to binary (division by 2 method):
1 / 2 = 0 remainder 1
2 / 2 = 1 remainder 0
5 / 2 = 2 remainder 1
11 / 2 = 5 remainder 1
23 / 2 = 11 remainder 1
46 / 2 = 23 remainder 0
Read remainders from bottom to top -> 101110. So 46_10 = 101110_2.
17. 1's complement arithmetic:
a) (-19) + 29 = 10 (binary ones-comp result 00001010)
b) 21 + 37 = 58 (binary ones-comp result 00111010)
18. Add (+80) and (-70) using 2's complement (8-bit):
+80 (8-bit) = 01010000, -70 (8-bit) = 10111010
Sum (binary) = 00001010 -> decimal 10
19. Decimal subtraction in 8-4-2-1 BCD using 9's complement:
a) Subtract 99 from 55: result = 55 - 99 = -44 -> negative; magnitude 44.
b) Subtract 478 from 893: result = 893 - 478 = 415.
20. Convert (6BA9)_16 to base2 and base8:
- Binary = 0110101110101001
- Octal = (65651)_8
21. Find X when (16)_10 = (100)_x:
(100)_x = 1*x^2 => x^2 = 16 => x = 4.
22. Convert the following:
a) 977_10 -> hex = 3D1
b) 657_10 -> octal = 1221
c) 754_10 -> binary = 1011110010
d) (10011)_6 -> decimal = 1303
23. 1's and 2's complements of (10001111)_2:
- 1's complement: 01110000
- 2's complement: 01110001
24. 9's complement of 6248 and express in 2421 code:
- 9's complement: 3751
- 2421 code mapping for digits (0-9):
0 -> 0000
1 -> 0001
2 -> 0010
3 -> 0011
4 -> 0100
5 -> 1011
6 -> 1100
7 -> 1101
8 -> 1110
9 -> 1111
- So 3 7 5 1 -> 0011 1101 1011 0001
25. Given X = 1010100 (84), Y = 1000011 (67). Compute X - Y using 2's complement:
- 7-bit: X=1010100, Y=1000011, 2's comp of Y = 0111101, add: 1010100 + 0111101 = 0010001 -> decimal 17
(which is 17)
26. Represent decimal 6248 in various codes:
- (i) BCD (8421): 0110 0010 0100 1000
- (ii) Excess-3: 1001 0101 0111 1011
- (iii) 2421: 1100 0010 0100 1110
- (iv) 6311 (greedy weight mapping): 1000 0011 0110 1011
27. Convert to decimal:
a) (4433)_5 = decimal 618
b) (1199)_12 = decimal 1989
28. Subtraction using 1's and 2's complement:
11010 - 10000: width 5; 1's method: 11010 + 01111 = 101001; 2's method: 11010 + 10000 = 101010. Decimal
result = 10
11010 - 1101: width 5; 1's method: 11010 + 10010 = 101100; 2's method: 11010 + 10011 = 101101. Decimal
result = 13
100 - 110000: width 6; 1's method: 000100 + 001111 = 0010011; 2's method: 000100 + 010000 = 0010100. Decimal
result = -44
29. How are negative numbers represented? (Examples for 4-bit representations for +7 to -8)
- Two's complement 4-bit range: -8..+7. Table (decimal -> 4-bit 2's complement):
7 -> 0111
6 -> 0110
5 -> 0101
4 -> 0100
3 -> 0011
2 -> 0010
1 -> 0001
0 -> 0000
-1 -> 1111
-2 -> 1110
-3 -> 1101
-4 -> 1100
-5 -> 1011
-6 -> 1010
-7 -> 1001
-8 -> 1000
30. Advantages of 2's complement:
- Single zero representation; easier adder logic; natural wrap-around for overflow; supports asymmetric
range [-2^{n-1} .. 2^{n-1}-1].
31. Convert to decimal:
- (10101001.0101)_2 = 169.3125 (decimal)
- (12020)_3 = 141.0 (decimal)
- (1023.2)_4 = 75.5 (decimal)
- (40123)_5 = 2538.0 (decimal)
- (0.354)_6 = 0.6574074074074073 (decimal)
- (45)_7 = 33.0 (decimal)
- (8.3)_9 = 8.333333333333334 (decimal)
- (A10)_12 = 1452.0 (decimal)
32/33. Weighted and non-weighted codes explained (see Q8).
34. Convert decimals 350.5, 14.0625, 102, 673.23 to bases 2,4,6,8,16 (approx for fractional):
- 350.5: binary=101011110.1, base4=11132.2, base6=1342.3, octal=536.4, hex=15E.8
- 14.0625: binary=1110.0001, base4=32.01, base6=22.0213, octal=16.04, hex=E.1
- 102: binary=1100110, base4=1212, base6=250, octal=146, hex=66
- 673.23: binary=1010100001.0011101011, base4=22201.032232011, base6=3041.121402514, octal=1241.1656050753,
hex=2A1.3AE147AE14
35. Possibility to construct 5-4-1-1 and 6-3-2-1 weighted codes:
- In principle yes; you must ensure unique 4-bit combinations map to decimal digits 0-9. One can test
feasibility by enumerating bit patterns; if 10 unique valid representations exist, it's possible.
Construction depends on desired properties (self-complementing etc.).
36. Exact number of bytes:
a) 32K bytes: assuming K=1024, 32*1024 = 32768 bytes.
b) 64M bytes: assuming M=1024*1024, 64*1024*1024 = 67108864 bytes.
37. (Repeat of Q24) 9's complement of 6248 -> 3751; 2421 code -> 0011 1101 1011 0001
38. Conversion problems:
a) 27.315_10 -> binary approx = 11011.01010000101000111101 (approx). Hex approx can be derived from binary
groups.
b) 3AB5_16 = 15029_10; 2A_16 = 42_10; difference = 14987_10.
c) (1101.0101)_2 to octal = 15.24
39. (615.25)_8 -> hex = 18D.54
40. Difference (3250 - 72546) using 10's complement:
- 3250 - 72546 = -69296 (direct computation). Using 10's complement method yields magnitude 69296 and
negative sign.
41. Perform:
a) 11010 - 1101 = 26 - 13 = 13 -> 01101 (if 5-bit).
b) 101011 - 100110 using 2's complement: 43 - 38 = 5 -> 00101.
42. Four-bit codes: examples and uses:
- 8421 BCD: weights 8,4,2,1; used to encode decimal digits.
- Excess-3: digit + 3, self-complementing.
- 2421: weights 2,4,2,1; variant with self-complementing properties.
- Gray (4-bit): non-weighted, single-bit change sequence.
43. Subtraction by 2's complement:
a) 111011 - 1010: align to 6 bits: 111011 - 001010 = 59 - 10 = 49 -> 110001.
b) 1100 - 1010110: align to 7 bits: 001100 - 1010110 = 12 - 86 = -74. Two's complement (7-bit)
representation: {0:>}
44. Subtraction via 9's complement:
a) 845 - 245: 845 - 245 = 600.
b) 236 - 673 = -437 (negative result).
45. Convert the following:
a) (A98B)_12 = decimal 18683 -> base 3 = 221121222
b) (38.65)_10 -> binary: integer 38 = 100110; fractional .65 -> multiply method gives repeating binary;
provide approximation if needed.
c) 10010011_2 = hex 93.
46. Convert then to octal:
a) (125F)_16 -> decimal 4703 -> octal 11137
b) (10111111)_2 -> decimal 191 -> octal 277
c) (392)_10 -> octal 610
47. Convert Gray to Binary (see Q7). 4-bit Gray code via mirror image:
0: 0000
1: 0001
2: 0011
3: 0010
4: 0110
5: 0111
6: 0101
7: 0100
8: 1100
9: 1101
10: 1111
11: 1110
12: 1010
13: 1011
14: 1001
15: 1000
48. Subtraction using radix complement (R's complement) and diminished radix (R-1's complement):
- Procedure: to compute A-B in base R, add A + (R's complement of B). If end carry occurs, discard carry ->
positive result. If no carry, result negative and magnitude is R's complement of sum.
49. 2421 code and code words for 0-9:
0 -> 0000
1 -> 0001
2 -> 0010
3 -> 0011
4 -> 0100
5 -> 1011
6 -> 1100
7 -> 1101
8 -> 1110
9 -> 1111
Difference from BCD (8421): 2421 uses different weights (2,4,2,1) and is self-complementing for many
implementations.
50. BCD arithmetic:
a) (79) + (177) = 256 -> BCD representation per digit: 256 (nibbles: 0010 0101 0110)
b) (481) + (178) = 659 -> BCD per digit: 0110 0101 1001
51. Subtraction using 2's complement:
a) 11100101 - 101011 -> 10111010 (decimal 186)
b) 12378 - 10230 = 2148
52. Encode decimal 493:
- Binary: 111101101
- BCD: 0100 1001 0011
- ASCII codes for characters '4','9','3': 52 57 51
- Excess-3 per digit: 0111 1100 0110
53. Binary codes: BCD and 2421 codes explained earlier (see Q8,Q49).
54. Convert:
a) 110001.1010010_2 -> hex approx = 31.A4
b) (AB)_16 = 171_10
c) (1234)_8 -> binary = 001010011100
55. BCD, Excess-3, alphanumeric codes: see earlier explanations; ASCII for alphanumeric characters;
BCD/Excess3 for decimal digits.
56. Represent decimal 4608:
- BCD (8421): 0100 0110 0000 1000
- Excess-3: 0111 1001 0011 1011
57. (-20) - (-10) = -10 (decimal). Representations in 8-bit two's complement: -20 = 11101100, -10 = 11110110.
58. Express in decimal:
a) (26.24)_8 = integer 2*8+6=22; fraction .24_8 = 2/8 + 4/64 = 0.25 + 0.0625 = 0.3125 -> 22.3125
b) (DADA.A)_16 -> decimal 56026.625
59. Represent 1999:
- BCD: 0001 1001 1001 1001
- 84-2-1 typically means 8421 BCD -> same as above
- 2421: 0001 1111 1111 1111
60. Express in binary:
a) (27.315)_10 approx binary = 11011.<fraction approx> (fraction non-terminating)
b) (16.5)_16 = decimal 22.3125 -> binary = 10110.0101
61. 100010 - 100110 (unsigned): 34 - 38 = -4 (negative). Using 2's complement yields representation of -4 for
chosen width.
62. Express to decimal:
a) (10110.0101)_2 = 22.3125
b) (16.5)_16 = 22.3125
63. Subtraction using 2's complement:
a) 1001 - 110101 -> 9 - 53 = -44
b) 101000 - 10101 -> 40 - 21 = 19 -> binary 10011
64. Subtraction using 1's complement:
a) 10011 - 10010 = 1
b) 100010 - 100110 = -4
65. Represent 6428:
- BCD: 0110 0100 0010 1000
- Excess-3: 1001 0111 0101 1011
- 2421: 1100 0100 0010 1110
66. Various number systems: binary (base2), octal (base8), decimal (base10), hexadecimal (base16).
Conversions via positional weights, repeated division for integer part, repeated multiplication for fraction.
67. Subtractions:
a) 97 - 255 = -158
b) (1111101)_2 (125) - (100111110)_2 (318) = -193
c) 255 - 408 = -153
68. Convert the following:
a) (53.625)_10 -> binary 110101.101 (0.625=5/8=.101)
b) (3FD)_16 -> binary 0011 1111 1101 -> 1111111101 (or padded groups)
c) (A69.8)_16 -> decimal 2665.5
69. Binary system and convert (101101110001.00101)_2 to octal:
- Group bits in 3 from decimal point: result = 5561.12_8 (see grouping in manual)
70. Rules for subtraction using complements:
- 1's complement: take 1's complement of subtrahend, add to minuend, if end-around carry add it; sign by MSB.
- 2's complement: take 2's complement of subtrahend, add to minuend; if carry out, discard carry ->
positive; if no carry, take 2's complement of sum and negative.
71. Reflected code: see Gray code (reflected Gray). Generation via mirror-image method.
72. Convert:
a) (25.325)_8 -> decimal = 21.416015625 -> binary = 010101.011010101
b) (BA.125)_16 -> decimal = 186.071533203125 -> binary = 10111010.000100100101