01How Computers Work (online)

Fully solved problem book

Eight-bit subtraction

Set 2 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 0033

Calculate 14 − 127 in eight-bit modular arithmetic.

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

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

Calculate 15 − 120 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00001111 and B=01111000.
  2. The unsigned values are A=15 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: 00001111 + 10001000.
  8. Keep only the lowest eight bits: 10010111.
  9. Normal integers give 15−120=-105.
  10. After modulo 256, the result is 151.
  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: 10010111 (151 unsigned)

Bitwise arithmetic · Problem 0035

Calculate 16 − 13 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00010000 and B=00001101.
  2. The unsigned values are A=16 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: 00010000 + 11110011.
  8. Keep only the lowest eight bits: 00000011.
  9. Normal integers give 16−13=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 0036

Calculate 16 − 76 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0037

Calculate 17 − 100 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0038

Calculate 17 − 106 in eight-bit modular arithmetic.

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

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

Final answer: 10100111 (167 unsigned)

Bitwise arithmetic · Problem 0039

Calculate 17 − 245 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00010001 and B=11110101.
  2. The unsigned values are A=17 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: 00010001 + 00001011.
  8. Keep only the lowest eight bits: 00011100.
  9. Normal integers give 17−245=-228.
  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 0040

Calculate 18 − 222 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00010010 and B=11011110.
  2. The unsigned values are A=18 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: 00010010 + 00100010.
  8. Keep only the lowest eight bits: 00110100.
  9. Normal integers give 18−222=-204.
  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 0041

Calculate 19 − 213 in eight-bit modular arithmetic.

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

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

Calculate 19 − 236 in eight-bit modular arithmetic.

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

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

Calculate 20 − 169 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0044

Calculate 21 − 70 in eight-bit modular arithmetic.

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

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

Calculate 22 − 252 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00010110 and B=11111100.
  2. The unsigned values are A=22 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: 00010110 + 00000100.
  8. Keep only the lowest eight bits: 00011010.
  9. Normal integers give 22−252=-230.
  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 0046

Calculate 23 − 28 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00010111 and B=00011100.
  2. The unsigned values are A=23 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: 00010111 + 11100100.
  8. Keep only the lowest eight bits: 11111011.
  9. Normal integers give 23−28=-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 0047

Calculate 23 − 86 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00010111 and B=01010110.
  2. The unsigned values are A=23 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: 00010111 + 10101010.
  8. Keep only the lowest eight bits: 11000001.
  9. Normal integers give 23−86=-63.
  10. After modulo 256, the result is 193.
  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: 11000001 (193 unsigned)

Bitwise arithmetic · Problem 0048

Calculate 23 − 143 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0049

Calculate 26 − 70 in eight-bit modular arithmetic.

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

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

Final answer: 11010100 (212 unsigned)

Bitwise arithmetic · Problem 0050

Calculate 26 − 118 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0051

Calculate 26 − 189 in eight-bit modular arithmetic.

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

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

Final answer: 01011101 (93 unsigned)

Bitwise arithmetic · Problem 0052

Calculate 26 − 241 in eight-bit modular arithmetic.

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

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

Final answer: 00101001 (41 unsigned)

Bitwise arithmetic · Problem 0053

Calculate 27 − 32 in eight-bit modular arithmetic.

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

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

Calculate 28 − 133 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0055

Calculate 28 − 177 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0056

Calculate 29 − 13 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00011101 and B=00001101.
  2. The unsigned values are A=29 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: 00011101 + 11110011.
  8. Keep only the lowest eight bits: 00010000.
  9. Normal integers give 29−13=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 0057

Calculate 29 − 215 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0058

Calculate 30 − 133 in eight-bit modular arithmetic.

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

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

Final answer: 10011001 (153 unsigned)

Bitwise arithmetic · Problem 0059

Calculate 31 − 210 in eight-bit modular arithmetic.

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

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

Final answer: 01001101 (77 unsigned)

Bitwise arithmetic · Problem 0060

Calculate 32 − 65 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00100000 and B=01000001.
  2. The unsigned values are A=32 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: 00100000 + 10111111.
  8. Keep only the lowest eight bits: 11011111.
  9. Normal integers give 32−65=-33.
  10. After modulo 256, the result is 223.
  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: 11011111 (223 unsigned)

Bitwise arithmetic · Problem 0061

Calculate 33 − 29 in eight-bit modular arithmetic.

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

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

Final answer: 00000100 (4 unsigned)

Bitwise arithmetic · Problem 0062

Calculate 33 − 66 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0063

Calculate 33 − 244 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0064

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