Skip to content
DLVSDigital Logic Visualizing System

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    10001

Binary 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
  1. 2’s complement of N = 1001
  2. M + complement = 1010 + 1001 = 10011
  3. A carry came out of the top digit: discard it. The answer is positive.
  4. Result = 11
Matches M − N computed directly.
1’s complement method
  1. 1’s complement of N = 1000
  2. M + complement = 1010 + 1000 = 10010
  3. A carry came out of the top digit: add it back at the bottom (end-around carry). The answer is positive.
  4. Result = 11
Matches M − N computed directly.

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
1A0B1M1CinSum=1Cout=1

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.