Binary Addition
Computers don’t just store numbers in binary - they do stuff with them. We will learn how to do binary addition and subtraction. In order to do subtraction, we also need to learn how to write negative numbers in binary using Two’s Compliment.
The point of learning this stuff is so you really understand how working with binary works. After all, computers do it quite a lot.
Watch the video and then answer the questions below.
Eight-minute video
You can also view this video on YouTube
Key Points
- All binary artithmatic in computers is performed using addition.
- To subtract, e.g.
4-3
, just do addition with negative numbers, e.g.4 + (-3)
- Negative numbers in binary are written using Two’s Compliment. You must decide in advance how many bits you are going to use to store them.
Binary Addition
Write the two numbers above each other. Working from right to left, add the columns of digits, carrying numbers to the next column as required.
101
+ 011
----
1000
Twos Compliment
To go from a positive number to a negative number, e.g. from 5
to -5
, you perform two steps:
- Invert each bit, (a 0 becomes a 1, a 1 becomes a 0)
- Add 1
So we go from 0101
, invert it to 1010
, and add 1
to get 1011
. Using the twos compliment method, 1011
is -5
.
Binary Subtraction
To perform a - b
, first take the twos compliment of b
, and add it to a
. For example, to do 0101 - 0101
(assuming we’re storing numbers as 4 bits), we take the twos compliment of 101
, getting 1011
, as above.
101
+ 1011
-----
10000
We’re working with 4-bits, so we strike off the first number, leaving 0000
.
Questions
1. Check your understanding
Use pen and paper to solve the following expressions then check your answers here.
Write your answers in binary. Do not use a prefix or any leading zeroes in your answers.
1. Addition
2. Two’s Compliment
Convert these numbers into their two’s compliment. Assume we’re working with numbers stored using 4 bits.
3. Subtraction
Assume we’re working with numbers stored using 4 bits. Negative numbers are stored using Two’s Compliment
Summary
In this section we learned how to do addition and subtraction with binary numbers.
- You should be able to find the Two’s Compliment of a binary number.
- You should be able to add and subtract numbers in binary.
In the next section we will learn binary multiplication and division.
- Previous
- Next