Logic Lab
Binary Arithmetic
Add, subtract, multiply and divide, and subtract using r’s and (r−1)’s complement, step by step.
Arithmetic in any base
Base
Result (base 2)10001
In decimal17
carry 11100
A 1011
+ B 110
─────
sum 10001Binary addition shows the carry row. Multiplication is shift and add: one shifted copy of A for every 1 in B. Division is repeated trial subtraction, one dividend bit at a time. Other bases show the result only.
Subtraction using complements (M − N)
Base rDigits
−
2’s complement method
- 2’s complement of N = 1001
- M + complement = 1010 + 1001 = 10011
- A carry came out of the top digit: discard it. The answer is positive.
- Result = 11
1’s complement method
- 1’s complement of N = 1000
- M + complement = 1010 + 1000 = 10010
- A carry came out of the top digit: add it back at the bottom (end-around carry). The answer is positive.
- Result = 11
The r’s complement of N is r^n − N, found by taking the (r−1)’s complement (subtract every digit from r−1) and adding 1. Both methods turn subtraction into addition, so one adder can do both jobs.
The circuit behind it: one adder/subtractor slice
ABMCin
M = 0 adds. M = 1 subtracts: the XOR gate inverts B (the 1’s complement) and Cin = 1 adds the extra 1, giving the 2’s complement. A row of these slices, with each Cout feeding the next Cin, subtracts whole numbers.