Adding or addition is a fundamental arithmetic operation. Of course, in binary it was not going to be different, and adding binary numbers is one of the most frequent operations that we are going to perform.

Fortunately, they are not very different from their decimal equivalents. In fact, in binary it is even simpler. We are simply going to add digit by digit from right to left, taking into account the carryovers.

It is also important that, if we are working with fixed-size binary numbers, we contemplate overflow and underflow.

Finally, in the case of subtractions, you should also know if you are working with unsigned or signed numbers.

## Binary addition

Binary addition is a basic operation in the binary system. It is similar to addition in the decimal system, but it is performed with only two digits `0`

and `1`

.

The summary of the process is as follows:

- Start by adding the bits from the right and continue to the left
- If the sum of two bits is
`1`

or`0`

, write the result below the bits and continue - If the sum is 2, then write a
`0`

and carry a`1`

to the next bit of higher weight

### Carry

In binary addition, a “carry” occurs when the sum of two bits produces a result that needs to be “carried” to the next bit position.

This happens when the sum of two bits is equal to 2, that is, when both bits we add are `1`

. In this case, the result is `0`

and the carry involves adding 1 when added to the next most significant bit.

### Example of binary addition

For example, to add the binary numbers `1011`

(11 in decimal) and `1101`

(13 in decimal)

```
1011
+ 1101
______
11000
```

The result is `11000`

, which is equal to 25 in decimal.

```
10101
+ 11
______
11000
```

## How to add binary numbers quickly

Binary addition is quite simple. However, binary numbers are generally very long, which makes it … somewhat heavy.

It is not normally an operation that you have to do by hand. But, if you ever have to do it, usually because your teacher feels like it, you should know very quick ways to do the addition.

In fact, it is very easy and very quick to add binary numbers. Let’s start by analyzing what we are going to find. First, let’s assume that we are not carrying.

- If both are
`0`

, the result is`0`

- If one is
`0`

and the other`1`

(or vice versa) “mesh”, and they make a`1`

- The only difficult part is when we have
`1`

and`1`

, which gives us a carry.

Now let’s see what happens when we do carry.

Here, the interesting thing is to see that, when we carry, all combinations overflow, except `0`

with `0`

.

That is, once the carry is activated, the `1`

that I take cannot go down until it finds `0`

and `0`

.

## Example

Let’s see it with an example. Suppose we want to add these two 12-bit binary numbers.

We start from the right, and look for `1`

with `1`

combinations. Here is where the carry is activated.

Next, we keep looking until we find a `0`

with `0`

. That’s where the carry can go down.

In the end, it’s as if the `1-1`

generates a `10`

. The `0`

stays in place, and the `1`

goes and goes until it finds a `0-0`

where it can go down.

Now, we just have to fill in the blocks we have defined. In the blocks without a carry, we apply the normal rules.

`0-0`

adds`0`

`0-1`

or`1-0`

, one meshes with the other, and gives`1`

Or, in other words, in the blocks without a carry “the `1`

s” command.

Now we arrive at the next block, which has a carry. Here “the `0`

s” command. If there is a `0`

in the bit we are adding, the result is `0`

. If not, `1`

.

And we would continue alternating between blocks with a carry, blocks without a carry, until we run out of numbers.

Lastly, you can also see it as the blocks without a carry are XOR, and those with a carry NXOR.

Which is less practical to operate, but allows you to use Hamlet’s mnemonic of “To Be or Not To Be”, so that many years from now you will still remember that binary additions are made in XOR and NXOR blocks:

## Bonus: How to quickly add 1 in binary

Special bonus, how to quickly add 1 to a binary number. A very simple operation, but since it is very common, it is convenient to know how to do it.

Fortunately, adding 1 in binary “is a piece of cake”. Simply

- Go through the binary number from the right
- Look for the first
`0`

you find, and change it to`1`

- From that position, towards the right, all
`0`

s.

For example, if we had to add 1 to `1000011111`

We look for the first `0`

We change it to `1`

and, from there to the right, all `0`

.

So the result is `1000100000`

. As you can see, adding one is very quick.