# Binary addition

Binary can be added together. Let's add 7 and 14 together as an example.

7

Decimal | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|

Binary | 0 | 0 | 1 | 1 | 1 |

14

Decimal | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|

Binary | 0 | 1 | 1 | 1 | 0 |

21

Decimal | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|

Binary | 1 | 0 | 1 | 0 | 1 |

The rules for addition are described below:

0+0 | 0 |

1+0 | 1 |

0+1 | 1 |

1+1 | 0 carry 1 |

1+1+1 | 1 carry 1 |

7 and 14 are `0111`

and `1110`

. We add the first digits, this gives us 1, since `1 + 0 = 1`

.

0111 |

1110 |

1 |

Next, we add 1 and 1. This gives us 2, which in binary is `10`

. So we write down 0, and carry the 1.

1 |
---|

0111 |

1110 |

01 |

Now, since we carried a bit, we have 3 bits to use. This gives us 3, which is represented as `11`

. So we write down 1 and carry the other 1.

1 |
---|

0111 |

1110 |

101 |

Since we carried 1, we need to add `1 + 0 + 1`

, which equals 2. This in binary is `10`

, so we write that down.

0111 |

1110 |

10101 |

This seems pretty simple, but binary addition overflow can occur.