01How Computers Work

Fully solved problem book

Eight-bit subtraction

Set 12 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 0353

Calculate 212 − 230 in eight-bit modular arithmetic.

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

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

Calculate 215 − 65 in eight-bit modular arithmetic.

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

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

Calculate 215 − 182 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=11010111 and B=10110110.
  2. The unsigned values are A=215 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: 11010111 + 01001010.
  8. Keep only the lowest eight bits: 00100001.
  9. Normal integers give 215−182=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 0356

Calculate 216 − 93 in eight-bit modular arithmetic.

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

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

Calculate 217 − 142 in eight-bit modular arithmetic.

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

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

Calculate 217 − 155 in eight-bit modular arithmetic.

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

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

Final answer: 00111110 (62 unsigned)

Bitwise arithmetic · Problem 0359

Calculate 217 − 233 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=11011001 and B=11101001.
  2. The unsigned values are A=217 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: 11011001 + 00010111.
  8. Keep only the lowest eight bits: 11110000.
  9. Normal integers give 217−233=-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 0360

Calculate 217 − 241 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0361

Calculate 218 − 86 in eight-bit modular arithmetic.

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

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

Calculate 218 − 202 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=11011010 and B=11001010.
  2. The unsigned values are A=218 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: 11011010 + 00110110.
  8. Keep only the lowest eight bits: 00010000.
  9. Normal integers give 218−202=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 0363

Calculate 219 − 33 in eight-bit modular arithmetic.

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

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

Calculate 219 − 87 in eight-bit modular arithmetic.

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

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

Calculate 219 − 228 in eight-bit modular arithmetic.

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

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

Final answer: 11110111 (247 unsigned)

Bitwise arithmetic · Problem 0366

Calculate 219 − 242 in eight-bit modular arithmetic.

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

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

Calculate 220 − 142 in eight-bit modular arithmetic.

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

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

Final answer: 01001110 (78 unsigned)

Bitwise arithmetic · Problem 0368

Calculate 220 − 194 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=11011100 and B=11000010.
  2. The unsigned values are A=220 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: 11011100 + 00111110.
  8. Keep only the lowest eight bits: 00011010.
  9. Normal integers give 220−194=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 0369

Calculate 220 − 255 in eight-bit modular arithmetic.

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

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

Final answer: 11011101 (221 unsigned)

Bitwise arithmetic · Problem 0370

Calculate 221 − 178 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=11011101 and B=10110010.
  2. The unsigned values are A=221 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: 11011101 + 01001110.
  8. Keep only the lowest eight bits: 00101011.
  9. Normal integers give 221−178=43.
  10. After modulo 256, the result is 43.
  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: 00101011 (43 unsigned)

Bitwise arithmetic · Problem 0371

Calculate 221 − 215 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=11011101 and B=11010111.
  2. The unsigned values are A=221 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: 11011101 + 00101001.
  8. Keep only the lowest eight bits: 00000110.
  9. Normal integers give 221−215=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 0372

Calculate 222 − 119 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=11011110 and B=01110111.
  2. The unsigned values are A=222 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: 11011110 + 10001001.
  8. Keep only the lowest eight bits: 01100111.
  9. Normal integers give 222−119=103.
  10. After modulo 256, the result is 103.
  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: 01100111 (103 unsigned)

Bitwise arithmetic · Problem 0373

Calculate 223 − 12 in eight-bit modular arithmetic.

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

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

Final answer: 11010011 (211 unsigned)

Bitwise arithmetic · Problem 0374

Calculate 223 − 42 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0375

Calculate 225 − 222 in eight-bit modular arithmetic.

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

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

Calculate 226 − 135 in eight-bit modular arithmetic.

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

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

Final answer: 01011011 (91 unsigned)

Bitwise arithmetic · Problem 0377

Calculate 229 − 118 in eight-bit modular arithmetic.

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

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

Final answer: 01101111 (111 unsigned)

Bitwise arithmetic · Problem 0378

Calculate 230 − 128 in eight-bit modular arithmetic.

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

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

Final answer: 01100110 (102 unsigned)

Bitwise arithmetic · Problem 0379

Calculate 230 − 170 in eight-bit modular arithmetic.

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

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

Final answer: 00111100 (60 unsigned)

Bitwise arithmetic · Problem 0380

Calculate 230 − 245 in eight-bit modular arithmetic.

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

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

Calculate 231 − 15 in eight-bit modular arithmetic.

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

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

Final answer: 11011000 (216 unsigned)

Bitwise arithmetic · Problem 0382

Calculate 231 − 108 in eight-bit modular arithmetic.

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

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

Calculate 231 − 139 in eight-bit modular arithmetic.

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

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

Final answer: 01011100 (92 unsigned)

Bitwise arithmetic · Problem 0384

Calculate 232 − 107 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=01101011.
  2. The unsigned values are A=232 and B=107.
  3. Rewrite subtraction as A + (NOT B) + 1.
  4. Invert every bit of B: 01101011 → 10010100.
  5. Add one to the inverted byte: 10010100 + 1 → 10010101.
  6. This new byte represents the modular additive inverse of B.
  7. Add A and modular −B: 11101000 + 10010101.
  8. Keep only the lowest eight bits: 01111101.
  9. Normal integers give 232−107=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)