askvity

How do you subtract in binary number system?

Published in Binary Arithmetic 3 mins read

Binary subtraction can be performed using a method similar to decimal subtraction, but it's more commonly done using the 2's complement method, which converts subtraction into addition. Here's how:

Methods for Binary Subtraction

There are two primary methods for binary subtraction: direct subtraction and the 2's complement method.

1. Direct Subtraction

This method is similar to decimal subtraction, borrowing from the next significant bit when necessary. The basic rules are:

  • 0 - 0 = 0
  • 1 - 0 = 1
  • 1 - 1 = 0
  • 0 - 1 = Borrow 1 from the next significant bit, making it 10 - 1 = 1

Example:

Let's subtract 011 (3 in decimal) from 101 (5 in decimal):

  101
- 011
-------
  010
  • Starting from the rightmost bit (least significant bit): 1 - 1 = 0
  • Next bit: 0 - 1. We need to borrow 1 from the leftmost bit. The leftmost 1 becomes 0, and the middle 0 becomes 10 (which is 2 in decimal). So, 10 - 1 = 1
  • Last bit: Now we have 0 - 0 = 0.

Therefore, 101 - 011 = 010 (2 in decimal).

2. 2's Complement Method

This method is generally preferred because it simplifies subtraction by converting it into addition. Here are the steps:

  • Step 1: Find the 1's complement of the subtrahend (the number being subtracted). To find the 1's complement, simply invert all the bits (change 0s to 1s and 1s to 0s).
  • Step 2: Find the 2's complement of the subtrahend. Add 1 to the 1's complement.
  • Step 3: Add the 2's complement of the subtrahend to the minuend (the number being subtracted from).
  • Step 4: If there is a carry-out bit (an extra 1 at the leftmost position), discard it. The remaining bits represent the result. If there is no carry-out, then take the 2's complement of the result; the answer is negative.

Example:

Let's subtract 011 (3 in decimal) from 101 (5 in decimal) using the 2's complement method:

  1. 1's complement of 011: 100
  2. 2's complement of 011: 100 + 1 = 101
  3. Add the 2's complement to the minuend:
  101
+ 101
-------
 1010
  1. Discard the carry-out: Discard the leftmost 1.

Therefore, the result is 010 (2 in decimal).

Another Example (Negative Result):

Subtract 101 (5) from 011 (3):

  1. 1's complement of 101: 010
  2. 2's complement of 101: 010 + 1 = 011
  3. Add the 2's complement to the minuend:
  011
+ 011
-------
  110
  1. There is no carry-out. Take the 2's complement of 110 to get the answer (and remember it's negative):

    • 1's complement of 110: 001
    • 2's complement of 110: 001 + 1 = 010

Therefore, the answer is -010 (-2 in decimal).

In summary, binary subtraction using the 2's complement method involves finding the 2's complement of the subtrahend and adding it to the minuend. Discard the carry-out if it exists to get the final result. This technique simplifies binary arithmetic in digital circuits.

Related Articles