zaro

How to Subtract Binary Numbers?

Published in Binary Arithmetic 3 mins read

Subtracting binary numbers can be performed using two primary methods: direct subtraction, which mimics decimal subtraction with binary rules, and the 1's complement method, which converts subtraction into an addition problem.

Direct Binary Subtraction

Direct binary subtraction follows rules similar to decimal subtraction, involving borrowing when a smaller digit is to be subtracted from a larger one.

Basic Rules for Binary Subtraction

The fundamental rules for subtracting single binary digits are:

Operation Result Borrow (from next higher bit)
0 - 0 0 0
1 - 0 1 0
1 - 1 0 0
0 - 1 1 1

The last rule (0 - 1) is crucial: if you need to subtract 1 from 0, you must borrow from the next higher-order bit. When you borrow, the '0' becomes '10' (binary for 2), and then 10 - 1 equals 1. The bit you borrowed from effectively reduces its value by 1.

Example of Direct Subtraction

Let's subtract 0110 (6 in decimal) from 1011 (11 in decimal):

  1011  (Minuend)
- 0110  (Subtrahend)
------
  1. Rightmost bit (LSB): 1 - 0 = 1
  2. Second bit from right: 1 - 1 = 0
  3. Third bit from right: 0 - 1. Here, we need to borrow from the next (leftmost) bit.
    • The leftmost '1' becomes '0'.
    • The '0' in the third position becomes '10'.
    • Now, 10 - 1 = 1.
  4. Leftmost bit (MSB): The original '1' became '0' due to borrowing. So, 0 - 0 = 0.

Combining the results, from right to left: 101 = 0101.

  ¹  (borrow)
  1 0¹ 1 1
- 0 1  1 0
--------
  0 1  0 1

So, 1011 - 0110 = 0101 (which is 11 - 6 = 5 in decimal).

Binary Subtraction Using 1's Complement

The 1's complement method simplifies binary subtraction by converting it into an addition problem, making it particularly useful in digital circuits. This method involves finding the 1's complement of the subtrahend and then adding it to the minuend.

Steps for 1's Complement Subtraction

To subtract binary numbers using the 1's complement method, follow these steps:

  1. Find the 1's complement of the subtrahend. The 1's complement is obtained by inverting all the bits of the number (changing all 0s to 1s and all 1s to 0s). Ensure that both the minuend and the subtrahend have the same number of bits; pad with leading zeros if necessary.
  2. Add the 1's complement of the subtrahend to the minuend. Perform standard binary addition.
  3. Examine the carryover from the most significant bit (MSB):
    • If a carryover (a '1' that extends beyond the original bit length) is generated, this indicates a positive result. Add this carryover back to the least significant bit (LSB) of the sum. This process is known as an end-around carry. The final result is the positive binary number.
    • If no carryover is generated, this indicates a negative result. To find the magnitude of the negative result, take the 1's complement of the sum obtained in step 2. The final answer will then be negative.

Example 1: Positive Result (with carryover)

Subtract 0110 (6) from 1011 (11) using 1's complement:

  1. Minuend: 1011
  2. Subtrahend: 0110
  3. 1's complement of subtrahend (0110): 1001
  4. Add minuend and 1's complement of subtrahend:
      1011  (Minuend)
    + 1001  (1's complement of 0110)
    -------
    (1)0100  (Sum with carry)
  5. Add the carryover to the LSB:
    The carryover is '1'. Add it to the LSB of 0100:
      0100
    +   1   (Carryover)
    -------
      0101

    The result is 0101 (which is 5 in decimal), which is correct (11 - 6 = 5).

Example 2: Negative Result (no carryover)

Subtract 1011 (11) from 0110 (6) using 1's complement:

  1. Minuend: 0110
  2. Subtrahend: 1011
  3. 1's complement of subtrahend (1011): 0100
  4. Add minuend and 1's complement of subtrahend:
      0110  (Minuend)
    + 0100  (1's complement of 1011)
    -------
      1010  (Sum)
  5. Check for carryover:
    There is no carryover from the leftmost bit. This indicates a negative result.
  6. Take 1's complement of the sum:
    The sum is 1010. Its 1's complement is 0101.
    The final answer is -0101 (which is -5 in decimal), which is correct (6 - 11 = -5).