01How Computers Work

Fully solved problem book

Eight-bit subtraction

Set 8 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 0225

Calculate 139 − 34 in eight-bit modular arithmetic.

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

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

Final answer: 01101001 (105 unsigned)

Bitwise arithmetic · Problem 0226

Calculate 139 − 85 in eight-bit modular arithmetic.

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

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

Final answer: 00110110 (54 unsigned)

Bitwise arithmetic · Problem 0227

Calculate 139 − 245 in eight-bit modular arithmetic.

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

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

Final answer: 10010110 (150 unsigned)

Bitwise arithmetic · Problem 0228

Calculate 140 − 252 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0229

Calculate 142 − 122 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0230

Calculate 142 − 208 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10001110 and B=11010000.
  2. The unsigned values are A=142 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: 10001110 + 00110000.
  8. Keep only the lowest eight bits: 10111110.
  9. Normal integers give 142−208=-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 0231

Calculate 143 − 191 in eight-bit modular arithmetic.

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

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

Final answer: 11010000 (208 unsigned)

Bitwise arithmetic · Problem 0232

Calculate 145 − 10 in eight-bit modular arithmetic.

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

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

Final answer: 10000111 (135 unsigned)

Bitwise arithmetic · Problem 0233

Calculate 145 − 86 in eight-bit modular arithmetic.

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

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

Final answer: 00111011 (59 unsigned)

Bitwise arithmetic · Problem 0234

Calculate 145 − 247 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0235

Calculate 146 − 56 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0236

Calculate 146 − 118 in eight-bit modular arithmetic.

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

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

Final answer: 00011100 (28 unsigned)

Bitwise arithmetic · Problem 0237

Calculate 147 − 75 in eight-bit modular arithmetic.

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

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

Final answer: 01001000 (72 unsigned)

Bitwise arithmetic · Problem 0238

Calculate 147 − 251 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0239

Calculate 148 − 117 in eight-bit modular arithmetic.

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

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

Calculate 149 − 207 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0241

Calculate 149 − 228 in eight-bit modular arithmetic.

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

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

Final answer: 10110001 (177 unsigned)

Bitwise arithmetic · Problem 0242

Calculate 150 − 41 in eight-bit modular arithmetic.

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

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

Final answer: 01101101 (109 unsigned)

Bitwise arithmetic · Problem 0243

Calculate 150 − 157 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0244

Calculate 150 − 197 in eight-bit modular arithmetic.

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

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

Final answer: 11010001 (209 unsigned)

Bitwise arithmetic · Problem 0245

Calculate 152 − 83 in eight-bit modular arithmetic.

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

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

Final answer: 01000101 (69 unsigned)

Bitwise arithmetic · Problem 0246

Calculate 152 − 121 in eight-bit modular arithmetic.

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

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

Calculate 152 − 233 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10011000 and B=11101001.
  2. The unsigned values are A=152 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: 10011000 + 00010111.
  8. Keep only the lowest eight bits: 10101111.
  9. Normal integers give 152−233=-81.
  10. After modulo 256, the result is 175.
  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: 10101111 (175 unsigned)

Bitwise arithmetic · Problem 0248

Calculate 152 − 237 in eight-bit modular arithmetic.

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

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

Calculate 153 − 4 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10011001 and B=00000100.
  2. The unsigned values are A=153 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: 10011001 + 11111100.
  8. Keep only the lowest eight bits: 10010101.
  9. Normal integers give 153−4=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 0250

Calculate 154 − 116 in eight-bit modular arithmetic.

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

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

Final answer: 00100110 (38 unsigned)

Bitwise arithmetic · Problem 0251

Calculate 154 − 123 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=10011010 and B=01111011.
  2. The unsigned values are A=154 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: 10011010 + 10000101.
  8. Keep only the lowest eight bits: 00011111.
  9. Normal integers give 154−123=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 0252

Calculate 154 − 254 in eight-bit modular arithmetic.

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

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

Final answer: 10011100 (156 unsigned)

Bitwise arithmetic · Problem 0253

Calculate 155 − 45 in eight-bit modular arithmetic.

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

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

Final answer: 01101110 (110 unsigned)

Bitwise arithmetic · Problem 0254

Calculate 155 − 145 in eight-bit modular arithmetic.

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

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

Calculate 156 − 168 in eight-bit modular arithmetic.

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

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

Final answer: 11110100 (244 unsigned)

Bitwise arithmetic · Problem 0256

Calculate 156 − 209 in eight-bit modular arithmetic.

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

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