Lesson 4 - Binary Subtration

How to Subtract in Binary

Binary subtraction is very similar to binary addition. Where we use the AND gate in addition, we use the XOR gate in subtraction.
0 XOR 0 = 0
1 XOR 0 = 1
1 XOR 1 = 0

binary subtraction
When we try to compute 0 - 1 in one digit place, we must borrow from the digit place to the left of it. We replace the one to the left with a zero. Then, in the current digit place, we compute 10 - 1 = 1. This is the same procedure that you do when you compute 10 - 9 in decimal.

Note: it is important to subtract the smaller number from the larger number. If we do this the other way around, we will compute a negative number without the negative sign. This would be erroneous.
0 XOR 1 = 1
However, 0 - 1 = -1 not 1.

Practice

Compute the 6-bit binary subtractions detailed below. Converting to decimal is not necessary.

  1. 100011 - 011011
  2. 101010 - 010101
  3. 001000 - 000001
  4. 100000 - 000001
  5. 100100 - 011111
Solutions
# Problem Solution In Decimal
1 100011 - 011011 001000 35 - 27 = 8
2 101010 - 010101 010101 42 - 21 = 21
3 001000 - 000001 000111 8 - 1 = 7
4 100000 - 000001 011111 32 - 1 = 31
5 100100 - 011111 000101 36 - 31 = 5

Binary Subtraction Circuits.

Just like binary addition, binary subtraction circuits come in two types: Half Subtractor Circuits and Full Subtractor Circuits (composed of half subtractor circuits). We will only concern ourselves with Half Circuits. The implementation of a Full Subtractor Circuit will be a challenge activity.

Half Subtractor Circuit Diagram

half subtractor circuit
The upper path can be thought of as a XOR b. It computes the subtraction of the two bits in their place. The lower path is (NOT a) AND b. This computes the borrow bit. The borrow bit indicates that we must borrow a 1 from the next digit to the left. This way when we compute 0 - 1 our borrow bit is 1, representing that we must take a 1 from the next digit to the left.

Activity 1

Now that you know how to subtract in binary, create a Half Subtractor Circuit within Minecraft that subtracts two 1-bit binary numbers. Hint: What logical gate do we use for subtraction?

Activity 2

Use what you know about carry bits to construct a circuit that computes the subtraction between two 2-bit binary numbers.

Activity 3 (Challenge Activity)

String together Half Subtractor Circuits to create a Full Subtractor Circuit. You will need to research how to implement a Full Subtractor Circuit.