01How Computers Work (online)

Fully solved problem book

Eight-bit subtraction

Set 4 of 14 · 32 worked questions. Predict your result before expanding the solution.

These worked traces are meant to build fluency through controlled variation. If several answers feel identical, try the next difficult value and look for the point where a carry, sign, branch, or selected memory address changes the outcome.

Bitwise arithmetic · Problem 0097

Calculate 57 − 182 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=00111001 and B=10110110.
  2. The unsigned values are A=57 and B=182.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 10110110 → 01001001.
  5. Add one to the inverted byte: 01001001 + 1 → 01001010.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 00111001 + 01001010.
  8. Keep only the lowest eight bits: 10000011.
  9. Normal integers give 57−182=-125.
  10. After modulo 256, the result is 131.
  11. The signed interpretation of the output byte is -125.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 10000011 (131 unsigned)

Bitwise arithmetic · Problem 0098

Calculate 58 − 143 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=00111010 and B=10001111.
  2. The unsigned values are A=58 and B=143.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 10001111 → 01110000.
  5. Add one to the inverted byte: 01110000 + 1 → 01110001.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 00111010 + 01110001.
  8. Keep only the lowest eight bits: 10101011.
  9. Normal integers give 58−143=-85.
  10. After modulo 256, the result is 171.
  11. The signed interpretation of the output byte is -85.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 10101011 (171 unsigned)

Bitwise arithmetic · Problem 0099

Calculate 58 − 245 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=00111010 and B=11110101.
  2. The unsigned values are A=58 and B=245.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 11110101 → 00001010.
  5. Add one to the inverted byte: 00001010 + 1 → 00001011.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 00111010 + 00001011.
  8. Keep only the lowest eight bits: 01000101.
  9. Normal integers give 58−245=-187.
  10. After modulo 256, the result is 69.
  11. The signed interpretation of the output byte is 69.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 01000101 (69 unsigned)

Bitwise arithmetic · Problem 0100

Calculate 59 − 170 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=00111011 and B=10101010.
  2. The unsigned values are A=59 and B=170.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 10101010 → 01010101.
  5. Add one to the inverted byte: 01010101 + 1 → 01010110.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 00111011 + 01010110.
  8. Keep only the lowest eight bits: 10010001.
  9. Normal integers give 59−170=-111.
  10. After modulo 256, the result is 145.
  11. The signed interpretation of the output byte is -111.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 10010001 (145 unsigned)

Bitwise arithmetic · Problem 0101

Calculate 59 − 173 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=00111011 and B=10101101.
  2. The unsigned values are A=59 and B=173.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 10101101 → 01010010.
  5. Add one to the inverted byte: 01010010 + 1 → 01010011.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 00111011 + 01010011.
  8. Keep only the lowest eight bits: 10001110.
  9. Normal integers give 59−173=-114.
  10. After modulo 256, the result is 142.
  11. The signed interpretation of the output byte is -114.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 10001110 (142 unsigned)

Bitwise arithmetic · Problem 0102

Calculate 60 − 73 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=00111100 and B=01001001.
  2. The unsigned values are A=60 and B=73.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 01001001 → 10110110.
  5. Add one to the inverted byte: 10110110 + 1 → 10110111.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 00111100 + 10110111.
  8. Keep only the lowest eight bits: 11110011.
  9. Normal integers give 60−73=-13.
  10. After modulo 256, the result is 243.
  11. The signed interpretation of the output byte is -13.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 11110011 (243 unsigned)

Bitwise arithmetic · Problem 0103

Calculate 62 − 226 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=00111110 and B=11100010.
  2. The unsigned values are A=62 and B=226.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 11100010 → 00011101.
  5. Add one to the inverted byte: 00011101 + 1 → 00011110.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 00111110 + 00011110.
  8. Keep only the lowest eight bits: 01011100.
  9. Normal integers give 62−226=-164.
  10. After modulo 256, the result is 92.
  11. The signed interpretation of the output byte is 92.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 01011100 (92 unsigned)

Bitwise arithmetic · Problem 0104

Calculate 63 − 222 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=00111111 and B=11011110.
  2. The unsigned values are A=63 and B=222.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 11011110 → 00100001.
  5. Add one to the inverted byte: 00100001 + 1 → 00100010.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 00111111 + 00100010.
  8. Keep only the lowest eight bits: 01100001.
  9. Normal integers give 63−222=-159.
  10. After modulo 256, the result is 97.
  11. The signed interpretation of the output byte is 97.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 01100001 (97 unsigned)

Bitwise arithmetic · Problem 0105

Calculate 63 − 251 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=00111111 and B=11111011.
  2. The unsigned values are A=63 and B=251.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 11111011 → 00000100.
  5. Add one to the inverted byte: 00000100 + 1 → 00000101.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 00111111 + 00000101.
  8. Keep only the lowest eight bits: 01000100.
  9. Normal integers give 63−251=-188.
  10. After modulo 256, the result is 68.
  11. The signed interpretation of the output byte is 68.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 01000100 (68 unsigned)

Bitwise arithmetic · Problem 0106

Calculate 64 − 151 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01000000 and B=10010111.
  2. The unsigned values are A=64 and B=151.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 10010111 → 01101000.
  5. Add one to the inverted byte: 01101000 + 1 → 01101001.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01000000 + 01101001.
  8. Keep only the lowest eight bits: 10101001.
  9. Normal integers give 64−151=-87.
  10. After modulo 256, the result is 169.
  11. The signed interpretation of the output byte is -87.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 10101001 (169 unsigned)

Bitwise arithmetic · Problem 0107

Calculate 65 − 168 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01000001 and B=10101000.
  2. The unsigned values are A=65 and B=168.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 10101000 → 01010111.
  5. Add one to the inverted byte: 01010111 + 1 → 01011000.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01000001 + 01011000.
  8. Keep only the lowest eight bits: 10011001.
  9. Normal integers give 65−168=-103.
  10. After modulo 256, the result is 153.
  11. The signed interpretation of the output byte is -103.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 10011001 (153 unsigned)

Bitwise arithmetic · Problem 0108

Calculate 67 − 32 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01000011 and B=00100000.
  2. The unsigned values are A=67 and B=32.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 00100000 → 11011111.
  5. Add one to the inverted byte: 11011111 + 1 → 11100000.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01000011 + 11100000.
  8. Keep only the lowest eight bits: 00100011.
  9. Normal integers give 67−32=35.
  10. After modulo 256, the result is 35.
  11. The signed interpretation of the output byte is 35.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 00100011 (35 unsigned)

Bitwise arithmetic · Problem 0109

Calculate 67 − 49 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01000011 and B=00110001.
  2. The unsigned values are A=67 and B=49.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 00110001 → 11001110.
  5. Add one to the inverted byte: 11001110 + 1 → 11001111.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01000011 + 11001111.
  8. Keep only the lowest eight bits: 00010010.
  9. Normal integers give 67−49=18.
  10. After modulo 256, the result is 18.
  11. The signed interpretation of the output byte is 18.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 00010010 (18 unsigned)

Bitwise arithmetic · Problem 0110

Calculate 68 − 135 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01000100 and B=10000111.
  2. The unsigned values are A=68 and B=135.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 10000111 → 01111000.
  5. Add one to the inverted byte: 01111000 + 1 → 01111001.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01000100 + 01111001.
  8. Keep only the lowest eight bits: 10111101.
  9. Normal integers give 68−135=-67.
  10. After modulo 256, the result is 189.
  11. The signed interpretation of the output byte is -67.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 10111101 (189 unsigned)

Bitwise arithmetic · Problem 0111

Calculate 68 − 212 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01000100 and B=11010100.
  2. The unsigned values are A=68 and B=212.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 11010100 → 00101011.
  5. Add one to the inverted byte: 00101011 + 1 → 00101100.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01000100 + 00101100.
  8. Keep only the lowest eight bits: 01110000.
  9. Normal integers give 68−212=-144.
  10. After modulo 256, the result is 112.
  11. The signed interpretation of the output byte is 112.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 01110000 (112 unsigned)

Bitwise arithmetic · Problem 0112

Calculate 69 − 209 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01000101 and B=11010001.
  2. The unsigned values are A=69 and B=209.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 11010001 → 00101110.
  5. Add one to the inverted byte: 00101110 + 1 → 00101111.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01000101 + 00101111.
  8. Keep only the lowest eight bits: 01110100.
  9. Normal integers give 69−209=-140.
  10. After modulo 256, the result is 116.
  11. The signed interpretation of the output byte is 116.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 01110100 (116 unsigned)

Bitwise arithmetic · Problem 0113

Calculate 70 − 4 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01000110 and B=00000100.
  2. The unsigned values are A=70 and B=4.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 00000100 → 11111011.
  5. Add one to the inverted byte: 11111011 + 1 → 11111100.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01000110 + 11111100.
  8. Keep only the lowest eight bits: 01000010.
  9. Normal integers give 70−4=66.
  10. After modulo 256, the result is 66.
  11. The signed interpretation of the output byte is 66.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 01000010 (66 unsigned)

Bitwise arithmetic · Problem 0114

Calculate 70 − 40 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01000110 and B=00101000.
  2. The unsigned values are A=70 and B=40.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 00101000 → 11010111.
  5. Add one to the inverted byte: 11010111 + 1 → 11011000.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01000110 + 11011000.
  8. Keep only the lowest eight bits: 00011110.
  9. Normal integers give 70−40=30.
  10. After modulo 256, the result is 30.
  11. The signed interpretation of the output byte is 30.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 00011110 (30 unsigned)

Bitwise arithmetic · Problem 0115

Calculate 70 − 49 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01000110 and B=00110001.
  2. The unsigned values are A=70 and B=49.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 00110001 → 11001110.
  5. Add one to the inverted byte: 11001110 + 1 → 11001111.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01000110 + 11001111.
  8. Keep only the lowest eight bits: 00010101.
  9. Normal integers give 70−49=21.
  10. After modulo 256, the result is 21.
  11. The signed interpretation of the output byte is 21.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 00010101 (21 unsigned)

Bitwise arithmetic · Problem 0116

Calculate 70 − 201 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01000110 and B=11001001.
  2. The unsigned values are A=70 and B=201.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 11001001 → 00110110.
  5. Add one to the inverted byte: 00110110 + 1 → 00110111.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01000110 + 00110111.
  8. Keep only the lowest eight bits: 01111101.
  9. Normal integers give 70−201=-131.
  10. After modulo 256, the result is 125.
  11. The signed interpretation of the output byte is 125.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 01111101 (125 unsigned)

Bitwise arithmetic · Problem 0117

Calculate 72 − 77 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01001000 and B=01001101.
  2. The unsigned values are A=72 and B=77.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 01001101 → 10110010.
  5. Add one to the inverted byte: 10110010 + 1 → 10110011.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01001000 + 10110011.
  8. Keep only the lowest eight bits: 11111011.
  9. Normal integers give 72−77=-5.
  10. After modulo 256, the result is 251.
  11. The signed interpretation of the output byte is -5.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 11111011 (251 unsigned)

Bitwise arithmetic · Problem 0118

Calculate 72 − 108 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01001000 and B=01101100.
  2. The unsigned values are A=72 and B=108.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 01101100 → 10010011.
  5. Add one to the inverted byte: 10010011 + 1 → 10010100.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01001000 + 10010100.
  8. Keep only the lowest eight bits: 11011100.
  9. Normal integers give 72−108=-36.
  10. After modulo 256, the result is 220.
  11. The signed interpretation of the output byte is -36.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 11011100 (220 unsigned)

Bitwise arithmetic · Problem 0119

Calculate 72 − 224 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01001000 and B=11100000.
  2. The unsigned values are A=72 and B=224.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 11100000 → 00011111.
  5. Add one to the inverted byte: 00011111 + 1 → 00100000.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01001000 + 00100000.
  8. Keep only the lowest eight bits: 01101000.
  9. Normal integers give 72−224=-152.
  10. After modulo 256, the result is 104.
  11. The signed interpretation of the output byte is 104.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 01101000 (104 unsigned)

Bitwise arithmetic · Problem 0120

Calculate 75 − 160 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01001011 and B=10100000.
  2. The unsigned values are A=75 and B=160.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 10100000 → 01011111.
  5. Add one to the inverted byte: 01011111 + 1 → 01100000.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01001011 + 01100000.
  8. Keep only the lowest eight bits: 10101011.
  9. Normal integers give 75−160=-85.
  10. After modulo 256, the result is 171.
  11. The signed interpretation of the output byte is -85.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 10101011 (171 unsigned)

Bitwise arithmetic · Problem 0121

Calculate 75 − 190 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01001011 and B=10111110.
  2. The unsigned values are A=75 and B=190.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 10111110 → 01000001.
  5. Add one to the inverted byte: 01000001 + 1 → 01000010.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01001011 + 01000010.
  8. Keep only the lowest eight bits: 10001101.
  9. Normal integers give 75−190=-115.
  10. After modulo 256, the result is 141.
  11. The signed interpretation of the output byte is -115.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 10001101 (141 unsigned)

Bitwise arithmetic · Problem 0122

Calculate 76 − 155 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01001100 and B=10011011.
  2. The unsigned values are A=76 and B=155.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 10011011 → 01100100.
  5. Add one to the inverted byte: 01100100 + 1 → 01100101.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01001100 + 01100101.
  8. Keep only the lowest eight bits: 10110001.
  9. Normal integers give 76−155=-79.
  10. After modulo 256, the result is 177.
  11. The signed interpretation of the output byte is -79.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 10110001 (177 unsigned)

Bitwise arithmetic · Problem 0123

Calculate 76 − 169 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01001100 and B=10101001.
  2. The unsigned values are A=76 and B=169.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 10101001 → 01010110.
  5. Add one to the inverted byte: 01010110 + 1 → 01010111.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01001100 + 01010111.
  8. Keep only the lowest eight bits: 10100011.
  9. Normal integers give 76−169=-93.
  10. After modulo 256, the result is 163.
  11. The signed interpretation of the output byte is -93.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 10100011 (163 unsigned)

Bitwise arithmetic · Problem 0124

Calculate 76 − 205 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01001100 and B=11001101.
  2. The unsigned values are A=76 and B=205.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 11001101 → 00110010.
  5. Add one to the inverted byte: 00110010 + 1 → 00110011.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01001100 + 00110011.
  8. Keep only the lowest eight bits: 01111111.
  9. Normal integers give 76−205=-129.
  10. After modulo 256, the result is 127.
  11. The signed interpretation of the output byte is 127.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 01111111 (127 unsigned)

Bitwise arithmetic · Problem 0125

Calculate 77 − 85 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01001101 and B=01010101.
  2. The unsigned values are A=77 and B=85.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 01010101 → 10101010.
  5. Add one to the inverted byte: 10101010 + 1 → 10101011.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01001101 + 10101011.
  8. Keep only the lowest eight bits: 11111000.
  9. Normal integers give 77−85=-8.
  10. After modulo 256, the result is 248.
  11. The signed interpretation of the output byte is -8.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 11111000 (248 unsigned)

Bitwise arithmetic · Problem 0126

Calculate 77 − 91 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01001101 and B=01011011.
  2. The unsigned values are A=77 and B=91.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 01011011 → 10100100.
  5. Add one to the inverted byte: 10100100 + 1 → 10100101.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01001101 + 10100101.
  8. Keep only the lowest eight bits: 11110010.
  9. Normal integers give 77−91=-14.
  10. After modulo 256, the result is 242.
  11. The signed interpretation of the output byte is -14.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 11110010 (242 unsigned)

Bitwise arithmetic · Problem 0127

Calculate 77 − 196 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01001101 and B=11000100.
  2. The unsigned values are A=77 and B=196.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 11000100 → 00111011.
  5. Add one to the inverted byte: 00111011 + 1 → 00111100.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01001101 + 00111100.
  8. Keep only the lowest eight bits: 10001001.
  9. Normal integers give 77−196=-119.
  10. After modulo 256, the result is 137.
  11. The signed interpretation of the output byte is -119.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 10001001 (137 unsigned)

Bitwise arithmetic · Problem 0128

Calculate 78 − 168 in eight-bit modular arithmetic.

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. Start with A=01001110 and B=10101000.
  2. The unsigned values are A=78 and B=168.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 10101000 → 01010111.
  5. Add one to the inverted byte: 01010111 + 1 → 01011000.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01001110 + 01011000.
  8. Keep only the lowest eight bits: 10100110.
  9. Normal integers give 78−168=-90.
  10. After modulo 256, the result is 166.
  11. The signed interpretation of the output byte is -90.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 10100110 (166 unsigned)