subtractor

To start, let’s keep our calculator as simple as possible. We’ll give it just two functions:

  • Add two numbers together
  • Subtract one number from another

We’ve already covered addition. Now we’ll see if we can adapt our adder to make a subtractor.

subtraction

Subtraction looks similar to addition:

  • Starting at the lowest column, we take each pair of digits and subtract one from the other
  • If we go below 0, then we carry negatively into the next column

For example, to calculate 147 - 52, starting with the lowest digits:

ABresultcarry
7-25
459-1
100

Giving the result 95.

In binary, this would be 10010011 - 110100:

ABresultcarry
101
101
011-1
001-1
111-1
010-1
001-1
100

Giving the result 1011111, which is 95.

representing this

As before, let’s look at how we want each pair of digits to behave:

  • 000
  • 101
  • 011, carry -1
  • 110

Ignoring the carry for now, this gives us the truth table . Like with the adder, this is just an XOR gate again. So it looks like we may be able to reuse much of our adder design.

carry

The carry’s truth table is . This doesn’t look familiar…

… but if we invert A, which corresponds to swapping the columns of the table, we get . This is just an AND gate.

So the carry is equivalent to NOT(A) AND(B).

coming soon
We’re still working on this part of the tutorial — come back later!

continue