01How Computers Work (online)

Fully solved problem book

Eight-bit subtraction

Set 7 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 0193

Calculate 118 − 69 in eight-bit modular arithmetic.

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

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

Final answer: 00110001 (49 unsigned)

Bitwise arithmetic · Problem 0194

Calculate 118 − 121 in eight-bit modular arithmetic.

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

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

Final answer: 11111101 (253 unsigned)

Bitwise arithmetic · Problem 0195

Calculate 120 − 27 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=01111000 and B=00011011.
  2. The unsigned values are A=120 and B=27.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 00011011 → 11100100.
  5. Add one to the inverted byte: 11100100 + 1 → 11100101.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01111000 + 11100101.
  8. Keep only the lowest eight bits: 01011101.
  9. Normal integers give 120−27=93.
  10. After modulo 256, the result is 93.
  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: 01011101 (93 unsigned)

Bitwise arithmetic · Problem 0196

Calculate 122 − 39 in eight-bit modular arithmetic.

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

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

Final answer: 01010011 (83 unsigned)

Bitwise arithmetic · Problem 0197

Calculate 122 − 55 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=01111010 and B=00110111.
  2. The unsigned values are A=122 and B=55.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 00110111 → 11001000.
  5. Add one to the inverted byte: 11001000 + 1 → 11001001.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01111010 + 11001001.
  8. Keep only the lowest eight bits: 01000011.
  9. Normal integers give 122−55=67.
  10. After modulo 256, the result is 67.
  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: 01000011 (67 unsigned)

Bitwise arithmetic · Problem 0198

Calculate 123 − 16 in eight-bit modular arithmetic.

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

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

Final answer: 01101011 (107 unsigned)

Bitwise arithmetic · Problem 0199

Calculate 123 − 43 in eight-bit modular arithmetic.

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

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

Final answer: 01010000 (80 unsigned)

Bitwise arithmetic · Problem 0200

Calculate 123 − 95 in eight-bit modular arithmetic.

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

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

Final answer: 00011100 (28 unsigned)

Bitwise arithmetic · Problem 0201

Calculate 123 − 131 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=01111011 and B=10000011.
  2. The unsigned values are A=123 and B=131.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 10000011 → 01111100.
  5. Add one to the inverted byte: 01111100 + 1 → 01111101.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 01111011 + 01111101.
  8. Keep only the lowest eight bits: 11111000.
  9. Normal integers give 123−131=-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 0202

Calculate 124 − 43 in eight-bit modular arithmetic.

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

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

Final answer: 01010001 (81 unsigned)

Bitwise arithmetic · Problem 0203

Calculate 124 − 52 in eight-bit modular arithmetic.

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

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

Final answer: 01001000 (72 unsigned)

Bitwise arithmetic · Problem 0204

Calculate 125 − 5 in eight-bit modular arithmetic.

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

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

Final answer: 01111000 (120 unsigned)

Bitwise arithmetic · Problem 0205

Calculate 127 − 135 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=01111111 and B=10000111.
  2. The unsigned values are A=127 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: 01111111 + 01111001.
  8. Keep only the lowest eight bits: 11111000.
  9. Normal integers give 127−135=-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 0206

Calculate 128 − 69 in eight-bit modular arithmetic.

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

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

Final answer: 00111011 (59 unsigned)

Bitwise arithmetic · Problem 0207

Calculate 128 − 105 in eight-bit modular arithmetic.

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

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

Final answer: 00010111 (23 unsigned)

Bitwise arithmetic · Problem 0208

Calculate 128 − 234 in eight-bit modular arithmetic.

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

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

Final answer: 10010110 (150 unsigned)

Bitwise arithmetic · Problem 0209

Calculate 129 − 8 in eight-bit modular arithmetic.

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

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

Final answer: 01111001 (121 unsigned)

Bitwise arithmetic · Problem 0210

Calculate 130 − 88 in eight-bit modular arithmetic.

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

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

Final answer: 00101010 (42 unsigned)

Bitwise arithmetic · Problem 0211

Calculate 130 − 109 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10000010 and B=01101101.
  2. The unsigned values are A=130 and B=109.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 01101101 → 10010010.
  5. Add one to the inverted byte: 10010010 + 1 → 10010011.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 10000010 + 10010011.
  8. Keep only the lowest eight bits: 00010101.
  9. Normal integers give 130−109=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 0212

Calculate 130 − 114 in eight-bit modular arithmetic.

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

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

Final answer: 00010000 (16 unsigned)

Bitwise arithmetic · Problem 0213

Calculate 130 − 213 in eight-bit modular arithmetic.

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

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

Final answer: 10101101 (173 unsigned)

Bitwise arithmetic · Problem 0214

Calculate 132 − 175 in eight-bit modular arithmetic.

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

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

Final answer: 11010101 (213 unsigned)

Bitwise arithmetic · Problem 0215

Calculate 132 − 225 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10000100 and B=11100001.
  2. The unsigned values are A=132 and B=225.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 11100001 → 00011110.
  5. Add one to the inverted byte: 00011110 + 1 → 00011111.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 10000100 + 00011111.
  8. Keep only the lowest eight bits: 10100011.
  9. Normal integers give 132−225=-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 0216

Calculate 133 − 254 in eight-bit modular arithmetic.

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

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

Final answer: 10000111 (135 unsigned)

Bitwise arithmetic · Problem 0217

Calculate 135 − 80 in eight-bit modular arithmetic.

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

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

Final answer: 00110111 (55 unsigned)

Bitwise arithmetic · Problem 0218

Calculate 136 − 28 in eight-bit modular arithmetic.

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

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

Final answer: 01101100 (108 unsigned)

Bitwise arithmetic · Problem 0219

Calculate 136 − 86 in eight-bit modular arithmetic.

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

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

Final answer: 00110010 (50 unsigned)

Bitwise arithmetic · Problem 0220

Calculate 136 − 233 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10001000 and B=11101001.
  2. The unsigned values are A=136 and B=233.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 11101001 → 00010110.
  5. Add one to the inverted byte: 00010110 + 1 → 00010111.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 10001000 + 00010111.
  8. Keep only the lowest eight bits: 10011111.
  9. Normal integers give 136−233=-97.
  10. After modulo 256, the result is 159.
  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: 10011111 (159 unsigned)

Bitwise arithmetic · Problem 0221

Calculate 137 − 30 in eight-bit modular arithmetic.

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

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

Final answer: 01101011 (107 unsigned)

Bitwise arithmetic · Problem 0222

Calculate 137 − 91 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10001001 and B=01011011.
  2. The unsigned values are A=137 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: 10001001 + 10100101.
  8. Keep only the lowest eight bits: 00101110.
  9. Normal integers give 137−91=46.
  10. After modulo 256, the result is 46.
  11. The signed interpretation of the output byte is 46.
  12. Discarding the ninth carry is valid for the fixed-width modular result; signed overflow is a separate question.

Final answer: 00101110 (46 unsigned)

Bitwise arithmetic · Problem 0223

Calculate 138 − 164 in eight-bit modular arithmetic.

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

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

Final answer: 11100110 (230 unsigned)

Bitwise arithmetic · Problem 0224

Calculate 138 − 232 in eight-bit modular arithmetic.

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

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

Final answer: 10100010 (162 unsigned)