Perform binary addition and subtraction

Resources | Subject Notes | Computer Science

Data Representation - Binary Addition and Subtraction

Objective

This section covers the fundamental concepts of binary representation and demonstrates how to perform binary addition and subtraction.

Binary Number System

The binary number system is a base-2 system, using only two digits: 0 and 1. Each position in a binary number represents a power of 2. For example, the binary number 1011 is equivalent to:

$$(1 \times 2^3) + (0 \times 2^2) + (1 \times 2^1) + (1 \times 2^0) = 8 + 0 + 2 + 1 = 11_{10}$$

Understanding binary is crucial because computers store and process information using binary.

Binary Addition

Binary addition follows similar rules to decimal addition, but with only two possible outcomes: 0 or 1. Here are the rules:

  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 0 = 1
  • 1 + 1 = 10 (which is 0 with a carry-over of 1)

Example: Add the binary numbers 1011 and 0110.

$$ \begin{array}{@{}c@{\,}c@{}c@{}c@{}c} & & 1 & 0 & 1 & 1 \\ + & & 0 & 1 & 1 & 0 \\ \hline \end{array} $$

Starting from the rightmost column:

  1. 1 + 0 = 1
  2. 1 + 1 = 10 (write down 0, carry over 1)
  3. 0 + 1 + 1 (carry) = 10 (write down 0, carry over 1)
  4. 1 + 0 + 1 (carry) = 10 (write down 0, carry over 1)

The final sum is 10001, which is equal to 21 in decimal.

Table: Binary Addition Example

Binary Decimal
1011 11
0110 6
10001
21

Binary Subtraction

Binary subtraction involves subtracting one binary number from another. Similar to addition, the rules are:

  • 0 - 0 = 0
  • 1 - 0 = 1
  • 1 - 1 = 0
  • 0 - 1 = ? (requires borrowing)

To perform subtraction, we borrow from the next more significant bit. If the bit to be subtracted is 0 and the corresponding bit in the next position is also 0, we need to borrow from the next higher position.

Example: Subtract the binary numbers 1101 and 1010.

$$ \begin{array}{@{}c@{\,}c@{}c@{}c@{}c} & 1 & 1 & 0 & 1 \\ - & 1 & 0 & 1 & 0 \\ \hline \end{array} $$

Starting from the rightmost column:

  1. 1 - 0 = 1
  2. 0 - 1 (borrow from the left): borrow from the 1 in the third position, making it 0. The 0 in the third position becomes 10 (which is 2 in decimal). So, 10 - 1 = 1)
  3. 0 - 0 = 0
  4. 1 - 1 = 0

The difference is 0111, which is equal to 7 in decimal.

Table: Binary Subtraction Example

Binary Decimal
1101 13
1010 10
0111
7

Summary

Binary addition and subtraction are fundamental operations in computer science. Understanding these concepts is essential for comprehending how computers manipulate data.