# Binary 1s and 2s Complement Forms

concept

Binary numbers are often stored in a computer in a form different to the "usual" binary we've been using up until now.
We use a different form because it sometimes makes doing binary arithmetic simpler and faster, which helps to make computers run faster, which is nice.

fact

The 1s (pronounced ones) complement of a binary number is obtained by changing all of the 1s to 0s and all the 0s to 1s

example

Convert \(1011_2\) to 1s complement form.

We just invert each bit to obtain: $$0100_2$$ The 2s complement form is by far the more useful. It makes binary subtraction a whole lot simpler by letting us encode negative numbers in a convenient way.

fact

The 2s complement is found by changing a binary number into its 1s complement form and then adding 1.

example

Convert \(10110_2\) to 2s complement form.

First we invert each bit to get 1s complement form: $$01001_2$$ Then we add 1 to get 2s complement form: $$01001_2 + 1_2 = 01010_2$$fact

A shortcut to get the 2s complement form of a number is:

- Starting from the rightmost digit and moving left copy out the digits up to and including the first 1
- Continuing to move left write the inverse of each digit (1s become 0s and 0s become 1s)

example

Convert \(10110_2\) to 2s complement form.

From the right the first digit is a 0 so we write \(0\). Then the next digit is our first 1 from the right so we add a 1 to get \(10\) From there we invert each digit and we end up with: $$01010_2$$ Just like above. 2s complement form is so great because encoding a negative number in 2s complement and then adding to a positive binary number will give you the result of the subtraction in 2s complement form.
This means you can do addition and subtraction using the one adder circuit.

fact

When creating a complement it's important to always write your answer using the same number of digits as the original number, even if that means having several leading 0s, otherwise you won't know how many leading 1s the original number had.

practice problems