01How Computers Work (online)

Fully solved problem book

Eight-bit subtraction

Set 3 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 0065

Calculate 34 − 225 in eight-bit modular arithmetic.

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

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

Final answer: 01000001 (65 unsigned)

Bitwise arithmetic · Problem 0066

Calculate 35 − 212 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0067

Calculate 36 − 13 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0068

Calculate 36 − 35 in eight-bit modular arithmetic.

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

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

Calculate 36 − 229 in eight-bit modular arithmetic.

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

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

Final answer: 00111111 (63 unsigned)

Bitwise arithmetic · Problem 0070

Calculate 37 − 13 in eight-bit modular arithmetic.

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

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

Calculate 37 − 59 in eight-bit modular arithmetic.

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

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

Final answer: 11101010 (234 unsigned)

Bitwise arithmetic · Problem 0072

Calculate 37 − 230 in eight-bit modular arithmetic.

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

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

Final answer: 00111111 (63 unsigned)

Bitwise arithmetic · Problem 0073

Calculate 38 − 56 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00100110 and B=00111000.
  2. The unsigned values are A=38 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: 00100110 + 11001000.
  8. Keep only the lowest eight bits: 11101110.
  9. Normal integers give 38−56=-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 0074

Calculate 38 − 246 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0075

Calculate 39 − 94 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0076

Calculate 39 − 222 in eight-bit modular arithmetic.

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

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

Final answer: 01001001 (73 unsigned)

Bitwise arithmetic · Problem 0077

Calculate 40 − 144 in eight-bit modular arithmetic.

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

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

Calculate 40 − 151 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0079

Calculate 40 − 217 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0080

Calculate 41 − 120 in eight-bit modular arithmetic.

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

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

Calculate 44 − 28 in eight-bit modular arithmetic.

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

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

Calculate 44 − 59 in eight-bit modular arithmetic.

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

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

Calculate 47 − 85 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00101111 and B=01010101.
  2. The unsigned values are A=47 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: 00101111 + 10101011.
  8. Keep only the lowest eight bits: 11011010.
  9. Normal integers give 47−85=-38.
  10. After modulo 256, the result is 218.
  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: 11011010 (218 unsigned)

Bitwise arithmetic · Problem 0084

Calculate 47 − 219 in eight-bit modular arithmetic.

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

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

Final answer: 01010100 (84 unsigned)

Bitwise arithmetic · Problem 0085

Calculate 48 − 1 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00110000 and B=00000001.
  2. The unsigned values are A=48 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: 00110000 + 11111111.
  8. Keep only the lowest eight bits: 00101111.
  9. Normal integers give 48−1=47.
  10. After modulo 256, the result is 47.
  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: 00101111 (47 unsigned)

Bitwise arithmetic · Problem 0086

Calculate 48 − 133 in eight-bit modular arithmetic.

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

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

Calculate 50 − 79 in eight-bit modular arithmetic.

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

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

Final answer: 11100011 (227 unsigned)

Bitwise arithmetic · Problem 0088

Calculate 51 − 2 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0089

Calculate 51 − 123 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0090

Calculate 53 − 81 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0091

Calculate 54 − 59 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00110110 and B=00111011.
  2. The unsigned values are A=54 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: 00110110 + 11000101.
  8. Keep only the lowest eight bits: 11111011.
  9. Normal integers give 54−59=-5.
  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 0092

Calculate 55 − 6 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0093

Calculate 55 − 233 in eight-bit modular arithmetic.

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

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

Calculate 55 − 248 in eight-bit modular arithmetic.

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

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

Final answer: 00111111 (63 unsigned)

Bitwise arithmetic · Problem 0095

Calculate 56 − 20 in eight-bit modular arithmetic.

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

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

Calculate 56 − 172 in eight-bit modular arithmetic.

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

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

Final answer: 10001100 (140 unsigned)