Adding binary numbers

By Martin McBride, 2017-02-21
Tags: binary addition
Categories: numbers

Computers calculate in binary. The basic operations are similar to how you would do arithmetic with a pencil and paper, but of course we must use binary rather than base 10. Once you get your head around it, binary is actually easier than base 10 in some ways.

Here we will look at binary addition.

The basics

Here are the basic addition results you need to know:

Binary addition

The first case are easy. 0 + 0 is 0, and 1 + 0 is 1.

1 + 1 equals 2, of course, but remember that 2 in binary is 10.

Similarly, 1 + 1 + 1 equals 3, but 3 in binary is 11.

Long addition

To add larger binary numbers, we use a technique which is similar to traditional long addition. For example, here is a 3 digit binary addition:

Binary addition

We add each column, starting at the right (least lowest place value). In the first column, 0 and 1 give 1.

Binary addition

In the second column, 0 and 0 give 0.

Binary addition

In the third column, 1 and 0 give 1.

Binary addition

We can check the result. Binary 100 is equal to 4, binary 001 is equal to 1. Binary 101 is equal to 5, so the answer is correct.

Long addition with carry

The previous sum was easy because none of the columns contained two 1s. In this next example, we have to carry digits over:

Binary addition

In the first column, 1 and 1 give 10 binary. This means that we put a 0 in the result, but we have 1 to carry over to the next column:

Binary addition

In the second column, we have 1 and 1 plus the extra 1 we carried over from before. This gives 11 in binary. So we put a 1 in the result and carry 1 over to the next column:

Binary addition

In the third column, we have 1 and 0 plus the extra 1 we carried over from before. This gives 10 in binary. So we put a 0 in the result and carry 1 over to the next column:

Binary addition

We haven't quite finished yet, because we still have the 1 carried over from last time. We create and extra column and put the carry value in that:

Binary addition

Once again, we can check our result. 111 binary is equal to 7, 011 binary is equal to 3, and 1010 binary is equal to 10.

See also

Sign up to the Creative Coding Newletter

Join my newsletter to receive occasional emails when new content is added, using the form below:

Popular tags

555 timer abstract data type abstraction addition algorithm and gate array ascii ascii85 base32 base64 battery binary binary encoding binary search bit block cipher block padding byte canvas colour coming soon computer music condition cryptographic attacks cryptography decomposition decryption deduplication dictionary attack encryption file server flash memory hard drive hashing hexadecimal hmac html image insertion sort ip address key derivation lamp linear search list mac mac address mesh network message authentication code music nand gate network storage none nor gate not gate op-amp or gate pixel private key python quantisation queue raid ram relational operator resources rgb rom search sort sound synthesis ssd star network supercollider svg switch symmetric encryption truth table turtle graphics yenc