01How Computers Work (online)

Fully solved problem book

Eight-bit subtraction

Set 9 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 0257

Calculate 157 − 178 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0258

Calculate 158 − 44 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0259

Calculate 158 − 235 in eight-bit modular arithmetic.

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

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

Final answer: 10110011 (179 unsigned)

Bitwise arithmetic · Problem 0260

Calculate 159 − 89 in eight-bit modular arithmetic.

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

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

Final answer: 01000110 (70 unsigned)

Bitwise arithmetic · Problem 0261

Calculate 159 − 126 in eight-bit modular arithmetic.

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

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

Final answer: 00100001 (33 unsigned)

Bitwise arithmetic · Problem 0262

Calculate 160 − 175 in eight-bit modular arithmetic.

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

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

Final answer: 11110001 (241 unsigned)

Bitwise arithmetic · Problem 0263

Calculate 162 − 30 in eight-bit modular arithmetic.

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

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

Final answer: 10000100 (132 unsigned)

Bitwise arithmetic · Problem 0264

Calculate 162 − 152 in eight-bit modular arithmetic.

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

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

Final answer: 00001010 (10 unsigned)

Bitwise arithmetic · Problem 0265

Calculate 162 − 178 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0266

Calculate 163 − 83 in eight-bit modular arithmetic.

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

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

Calculate 163 − 134 in eight-bit modular arithmetic.

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

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

Final answer: 00011101 (29 unsigned)

Bitwise arithmetic · Problem 0268

Calculate 163 − 141 in eight-bit modular arithmetic.

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

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

Final answer: 00010110 (22 unsigned)

Bitwise arithmetic · Problem 0269

Calculate 163 − 158 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0270

Calculate 163 − 169 in eight-bit modular arithmetic.

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

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

Final answer: 11111010 (250 unsigned)

Bitwise arithmetic · Problem 0271

Calculate 163 − 178 in eight-bit modular arithmetic.

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

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

Final answer: 11110001 (241 unsigned)

Bitwise arithmetic · Problem 0272

Calculate 164 − 148 in eight-bit modular arithmetic.

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

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

Calculate 164 − 164 in eight-bit modular arithmetic.

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

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

Final answer: 00000000 (0 unsigned)

Bitwise arithmetic · Problem 0274

Calculate 164 − 197 in eight-bit modular arithmetic.

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

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

Final answer: 11011111 (223 unsigned)

Bitwise arithmetic · Problem 0275

Calculate 164 − 210 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0276

Calculate 164 − 251 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10100100 and B=11111011.
  2. The unsigned values are A=164 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: 10100100 + 00000101.
  8. Keep only the lowest eight bits: 10101001.
  9. Normal integers give 164−251=-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 0277

Calculate 165 − 25 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0278

Calculate 165 − 162 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0279

Calculate 167 − 150 in eight-bit modular arithmetic.

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

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

Final answer: 00010001 (17 unsigned)

Bitwise arithmetic · Problem 0280

Calculate 167 − 166 in eight-bit modular arithmetic.

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

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

Final answer: 00000001 (1 unsigned)

Bitwise arithmetic · Problem 0281

Calculate 168 − 64 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10101000 and B=01000000.
  2. The unsigned values are A=168 and B=64.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 01000000 → 10111111.
  5. Add one to the inverted byte: 10111111 + 1 → 11000000.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 10101000 + 11000000.
  8. Keep only the lowest eight bits: 01101000.
  9. Normal integers give 168−64=104.
  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 0282

Calculate 169 − 48 in eight-bit modular arithmetic.

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

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

Calculate 169 − 94 in eight-bit modular arithmetic.

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

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

Final answer: 01001011 (75 unsigned)

Bitwise arithmetic · Problem 0284

Calculate 170 − 36 in eight-bit modular arithmetic.

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

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

Final answer: 10000110 (134 unsigned)

Bitwise arithmetic · Problem 0285

Calculate 170 − 76 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0286

Calculate 170 − 202 in eight-bit modular arithmetic.

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

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

Final answer: 11100000 (224 unsigned)

Bitwise arithmetic · Problem 0287

Calculate 170 − 253 in eight-bit modular arithmetic.

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

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

Calculate 171 − 75 in eight-bit modular arithmetic.

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

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

Final answer: 01100000 (96 unsigned)