01How Computers Work

Fully solved problem book

Eight-bit subtraction

Set 10 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 0289

Calculate 172 − 166 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10101100 and B=10100110.
  2. The unsigned values are A=172 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: 10101100 + 01011010.
  8. Keep only the lowest eight bits: 00000110.
  9. Normal integers give 172−166=6.
  10. After modulo 256, the result is 6.
  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: 00000110 (6 unsigned)

Bitwise arithmetic · Problem 0290

Calculate 173 − 40 in eight-bit modular arithmetic.

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

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

Final answer: 10000101 (133 unsigned)

Bitwise arithmetic · Problem 0291

Calculate 173 − 92 in eight-bit modular arithmetic.

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

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

Calculate 173 − 215 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0293

Calculate 174 − 119 in eight-bit modular arithmetic.

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

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

Calculate 176 − 43 in eight-bit modular arithmetic.

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

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

Final answer: 10000101 (133 unsigned)

Bitwise arithmetic · Problem 0295

Calculate 176 − 64 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10110000 and B=01000000.
  2. The unsigned values are A=176 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: 10110000 + 11000000.
  8. Keep only the lowest eight bits: 01110000.
  9. Normal integers give 176−64=112.
  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 0296

Calculate 176 − 126 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10110000 and B=01111110.
  2. The unsigned values are A=176 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: 10110000 + 10000010.
  8. Keep only the lowest eight bits: 00110010.
  9. Normal integers give 176−126=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 0297

Calculate 176 − 150 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10110000 and B=10010110.
  2. The unsigned values are A=176 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: 10110000 + 01101010.
  8. Keep only the lowest eight bits: 00011010.
  9. Normal integers give 176−150=26.
  10. After modulo 256, the result is 26.
  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: 00011010 (26 unsigned)

Bitwise arithmetic · Problem 0298

Calculate 176 − 178 in eight-bit modular arithmetic.

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

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

Final answer: 11111110 (254 unsigned)

Bitwise arithmetic · Problem 0299

Calculate 177 − 9 in eight-bit modular arithmetic.

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

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

Final answer: 10101000 (168 unsigned)

Bitwise arithmetic · Problem 0300

Calculate 177 − 40 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10110001 and B=00101000.
  2. The unsigned values are A=177 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: 10110001 + 11011000.
  8. Keep only the lowest eight bits: 10001001.
  9. Normal integers give 177−40=137.
  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 0301

Calculate 177 − 61 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10110001 and B=00111101.
  2. The unsigned values are A=177 and B=61.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 00111101 → 11000010.
  5. Add one to the inverted byte: 11000010 + 1 → 11000011.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 10110001 + 11000011.
  8. Keep only the lowest eight bits: 01110100.
  9. Normal integers give 177−61=116.
  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 0302

Calculate 178 − 199 in eight-bit modular arithmetic.

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

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

Calculate 179 − 8 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10110011 and B=00001000.
  2. The unsigned values are A=179 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: 10110011 + 11111000.
  8. Keep only the lowest eight bits: 10101011.
  9. Normal integers give 179−8=171.
  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 0304

Calculate 179 − 22 in eight-bit modular arithmetic.

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

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

Final answer: 10011101 (157 unsigned)

Bitwise arithmetic · Problem 0305

Calculate 180 − 50 in eight-bit modular arithmetic.

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

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

Final answer: 10000010 (130 unsigned)

Bitwise arithmetic · Problem 0306

Calculate 181 − 58 in eight-bit modular arithmetic.

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

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

Final answer: 01111011 (123 unsigned)

Bitwise arithmetic · Problem 0307

Calculate 182 − 29 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10110110 and B=00011101.
  2. The unsigned values are A=182 and B=29.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 00011101 → 11100010.
  5. Add one to the inverted byte: 11100010 + 1 → 11100011.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 10110110 + 11100011.
  8. Keep only the lowest eight bits: 10011001.
  9. Normal integers give 182−29=153.
  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 0308

Calculate 184 − 4 in eight-bit modular arithmetic.

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

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

Final answer: 10110100 (180 unsigned)

Bitwise arithmetic · Problem 0309

Calculate 184 − 76 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10111000 and B=01001100.
  2. The unsigned values are A=184 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: 10111000 + 10110100.
  8. Keep only the lowest eight bits: 01101100.
  9. Normal integers give 184−76=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 0310

Calculate 184 − 148 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10111000 and B=10010100.
  2. The unsigned values are A=184 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: 10111000 + 01101100.
  8. Keep only the lowest eight bits: 00100100.
  9. Normal integers give 184−148=36.
  10. After modulo 256, the result is 36.
  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: 00100100 (36 unsigned)

Bitwise arithmetic · Problem 0311

Calculate 184 − 176 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0312

Calculate 184 − 197 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10111000 and B=11000101.
  2. The unsigned values are A=184 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: 10111000 + 00111011.
  8. Keep only the lowest eight bits: 11110011.
  9. Normal integers give 184−197=-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 0313

Calculate 184 − 250 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0314

Calculate 186 − 131 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10111010 and B=10000011.
  2. The unsigned values are A=186 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: 10111010 + 01111101.
  8. Keep only the lowest eight bits: 00110111.
  9. Normal integers give 186−131=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 0315

Calculate 186 − 185 in eight-bit modular arithmetic.

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

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

Calculate 187 − 38 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0317

Calculate 187 − 56 in eight-bit modular arithmetic.

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

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

Calculate 188 − 29 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10111100 and B=00011101.
  2. The unsigned values are A=188 and B=29.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 00011101 → 11100010.
  5. Add one to the inverted byte: 11100010 + 1 → 11100011.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 10111100 + 11100011.
  8. Keep only the lowest eight bits: 10011111.
  9. Normal integers give 188−29=159.
  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 0319

Calculate 188 − 157 in eight-bit modular arithmetic.

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

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

Final answer: 00011111 (31 unsigned)

Bitwise arithmetic · Problem 0320

Calculate 189 − 240 in eight-bit modular arithmetic.

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

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

Final answer: 11001101 (205 unsigned)