01How Computers Work (online)

Fully solved problem book

Eight-bit subtraction

Set 1 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 0001

Calculate 0 − 180 in eight-bit modular arithmetic.

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

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

Final answer: 01001100 (76 unsigned)

Bitwise arithmetic · Problem 0002

Calculate 0 − 198 in eight-bit modular arithmetic.

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

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

Final answer: 00111010 (58 unsigned)

Bitwise arithmetic · Problem 0003

Calculate 0 − 200 in eight-bit modular arithmetic.

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

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

Final answer: 00111000 (56 unsigned)

Bitwise arithmetic · Problem 0004

Calculate 0 − 204 in eight-bit modular arithmetic.

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

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

Calculate 0 − 238 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0006

Calculate 1 − 14 in eight-bit modular arithmetic.

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

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

Final answer: 11110011 (243 unsigned)

Bitwise arithmetic · Problem 0007

Calculate 1 − 50 in eight-bit modular arithmetic.

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

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

Calculate 1 − 93 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00000001 and B=01011101.
  2. The unsigned values are A=1 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: 00000001 + 10100011.
  8. Keep only the lowest eight bits: 10100100.
  9. Normal integers give 1−93=-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 0009

Calculate 1 − 174 in eight-bit modular arithmetic.

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

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

Final answer: 01010011 (83 unsigned)

Bitwise arithmetic · Problem 0010

Calculate 1 − 250 in eight-bit modular arithmetic.

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

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

Final answer: 00000111 (7 unsigned)

Bitwise arithmetic · Problem 0011

Calculate 1 − 253 in eight-bit modular arithmetic.

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

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

Calculate 2 − 76 in eight-bit modular arithmetic.

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

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

Final answer: 10110110 (182 unsigned)

Bitwise arithmetic · Problem 0013

Calculate 3 − 209 in eight-bit modular arithmetic.

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

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

Final answer: 00110010 (50 unsigned)

Bitwise arithmetic · Problem 0014

Calculate 5 − 112 in eight-bit modular arithmetic.

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

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

Calculate 5 − 225 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00000101 and B=11100001.
  2. The unsigned values are A=5 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: 00000101 + 00011111.
  8. Keep only the lowest eight bits: 00100100.
  9. Normal integers give 5−225=-220.
  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 0016

Calculate 6 − 74 in eight-bit modular arithmetic.

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

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

Final answer: 10111100 (188 unsigned)

Bitwise arithmetic · Problem 0017

Calculate 6 − 138 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0018

Calculate 6 − 244 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00000110 and B=11110100.
  2. The unsigned values are A=6 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: 00000110 + 00001100.
  8. Keep only the lowest eight bits: 00010010.
  9. Normal integers give 6−244=-238.
  10. After modulo 256, the result is 18.
  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: 00010010 (18 unsigned)

Bitwise arithmetic · Problem 0019

Calculate 7 − 44 in eight-bit modular arithmetic.

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

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

Final answer: 11011011 (219 unsigned)

Bitwise arithmetic · Problem 0020

Calculate 7 − 161 in eight-bit modular arithmetic.

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

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

Calculate 8 − 7 in eight-bit modular arithmetic.

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

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

Calculate 8 − 90 in eight-bit modular arithmetic.

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

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

Final answer: 10101110 (174 unsigned)

Bitwise arithmetic · Problem 0023

Calculate 8 − 151 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0024

Calculate 8 − 236 in eight-bit modular arithmetic.

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

Reveal detailed solution →
  1. Start with A=00001000 and B=11101100.
  2. The unsigned values are A=8 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: 00001000 + 00010100.
  8. Keep only the lowest eight bits: 00011100.
  9. Normal integers give 8−236=-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 0025

Calculate 8 − 243 in eight-bit modular arithmetic.

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

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

Final answer: 00010101 (21 unsigned)

Bitwise arithmetic · Problem 0026

Calculate 9 − 2 in eight-bit modular arithmetic.

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

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

Final answer: 00000111 (7 unsigned)

Bitwise arithmetic · Problem 0027

Calculate 9 − 169 in eight-bit modular arithmetic.

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

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

Final answer: 01100000 (96 unsigned)

Bitwise arithmetic · Problem 0028

Calculate 9 − 180 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0029

Calculate 9 − 198 in eight-bit modular arithmetic.

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

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

Final answer: 01000011 (67 unsigned)

Bitwise arithmetic · Problem 0030

Calculate 12 − 175 in eight-bit modular arithmetic.

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

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

Calculate 13 − 4 in eight-bit modular arithmetic.

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

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

Bitwise arithmetic · Problem 0032

Calculate 13 − 239 in eight-bit modular arithmetic.

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

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

Final answer: 00011110 (30 unsigned)