01How Computers Work

Fully solved problem book

Eight-bit subtraction

Set 13 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 0385

Calculate 232 − 235 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=11101000 and B=11101011.
  2. The unsigned values are A=232 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: 11101000 + 00010101.
  8. Keep only the lowest eight bits: 11111101.
  9. Normal integers give 232−235=-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 0386

Calculate 233 − 75 in eight-bit modular arithmetic.

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

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

Final answer: 10011110 (158 unsigned)

Bitwise arithmetic · Problem 0387

Calculate 234 − 31 in eight-bit modular arithmetic.

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

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

Final answer: 11001011 (203 unsigned)

Bitwise arithmetic · Problem 0388

Calculate 235 − 116 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0389

Calculate 235 − 227 in eight-bit modular arithmetic.

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

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

Calculate 236 − 29 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=11101100 and B=00011101.
  2. The unsigned values are A=236 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: 11101100 + 11100011.
  8. Keep only the lowest eight bits: 11001111.
  9. Normal integers give 236−29=207.
  10. After modulo 256, the result is 207.
  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: 11001111 (207 unsigned)

Bitwise arithmetic · Problem 0391

Calculate 236 − 211 in eight-bit modular arithmetic.

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

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

Final answer: 00011001 (25 unsigned)

Bitwise arithmetic · Problem 0392

Calculate 236 − 225 in eight-bit modular arithmetic.

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

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

Final answer: 00001011 (11 unsigned)

Bitwise arithmetic · Problem 0393

Calculate 236 − 229 in eight-bit modular arithmetic.

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

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

Final answer: 00000111 (7 unsigned)

Bitwise arithmetic · Problem 0394

Calculate 237 − 1 in eight-bit modular arithmetic.

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

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

Final answer: 11101100 (236 unsigned)

Bitwise arithmetic · Problem 0395

Calculate 238 − 34 in eight-bit modular arithmetic.

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

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

Final answer: 11001100 (204 unsigned)

Bitwise arithmetic · Problem 0396

Calculate 239 − 114 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=11101111 and B=01110010.
  2. The unsigned values are A=239 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: 11101111 + 10001110.
  8. Keep only the lowest eight bits: 01111101.
  9. Normal integers give 239−114=125.
  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 0397

Calculate 240 − 182 in eight-bit modular arithmetic.

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

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

Final answer: 00111010 (58 unsigned)

Bitwise arithmetic · Problem 0398

Calculate 240 − 188 in eight-bit modular arithmetic.

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

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

Final answer: 00110100 (52 unsigned)

Bitwise arithmetic · Problem 0399

Calculate 240 − 194 in eight-bit modular arithmetic.

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

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

Calculate 241 − 251 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=11110001 and B=11111011.
  2. The unsigned values are A=241 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: 11110001 + 00000101.
  8. Keep only the lowest eight bits: 11110110.
  9. Normal integers give 241−251=-10.
  10. After modulo 256, the result is 246.
  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: 11110110 (246 unsigned)

Bitwise arithmetic · Problem 0401

Calculate 242 − 218 in eight-bit modular arithmetic.

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

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

Final answer: 00011000 (24 unsigned)

Bitwise arithmetic · Problem 0402

Calculate 243 − 10 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0403

Calculate 243 − 67 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0404

Calculate 243 − 124 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0405

Calculate 244 − 101 in eight-bit modular arithmetic.

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

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

Final answer: 10001111 (143 unsigned)

Bitwise arithmetic · Problem 0406

Calculate 244 − 124 in eight-bit modular arithmetic.

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

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

Calculate 245 − 9 in eight-bit modular arithmetic.

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

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

Final answer: 11101100 (236 unsigned)

Bitwise arithmetic · Problem 0408

Calculate 245 − 59 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0409

Calculate 246 − 123 in eight-bit modular arithmetic.

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

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

Calculate 246 − 172 in eight-bit modular arithmetic.

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

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

Final answer: 01001010 (74 unsigned)

Bitwise arithmetic · Problem 0411

Calculate 247 − 197 in eight-bit modular arithmetic.

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

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

Calculate 247 − 208 in eight-bit modular arithmetic.

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

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

Final answer: 00100111 (39 unsigned)

Bitwise arithmetic · Problem 0413

Calculate 249 − 166 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=11111001 and B=10100110.
  2. The unsigned values are A=249 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: 11111001 + 01011010.
  8. Keep only the lowest eight bits: 01010011.
  9. Normal integers give 249−166=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 0414

Calculate 252 − 1 in eight-bit modular arithmetic.

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

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

Calculate 252 − 14 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0416

Calculate 252 − 86 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=11111100 and B=01010110.
  2. The unsigned values are A=252 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: 11111100 + 10101010.
  8. Keep only the lowest eight bits: 10100110.
  9. Normal integers give 252−86=166.
  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)