## Binary

Binary is a format of presenting a number, but instead of our usual base ten format of counting, we use base two.

For example, $1010_2$ in binary would be $10_{10}$ as shown by the following:

$$\begin{array}{c}1&&0&&1&&0&\\1\cdot2^3&+&0\cdot2^2&+&1\cdot2^1&+&0\cdot2^0&=10_{10}\end{array}$$

### To Decimal

To convert numbers from binary to decimal, you need to do the following:

$$\begin{array}{l}
1:n=0\\
2:\text{Starting from the first digit on the right, check if it is 1}\\
\quad2.1:\text{If it is 1, add }2^n\text{ to your answer}\\
3:\text{If you have checked every digit, end}\\
4:\text{Add 1 to }n\text{ and return to step 2}
\end{array}$$

$$1010_2=1\cdot2^3+0\cdot2^2+1\cdot2^1+0\cdot2^0 = 10_{10}$$

### From Decimal

To convert numbers from decimal to binary, you need to do the following:

$$\begin{array}{l}
1:\text{Divide the number by 2}\\
2:\text{If the new number is an integer, add 0}\\
\quad2.1:\text{If not, add 1}\\
\quad2.2:\text{Round down to the nearest integer}\\
3:\text{If the number = 0, end}\\
4:\text{Return to step 1}
\end{array}$$

If recognize the number as a power of two $2^n$, such as $1024$, then you can just write the number as $1$ followed by $n$ $0$'s.

To tell how many bits (digits) you require to represent a number in binary, you can use the equation $\left\lceil\log(n)\right\rceil$.

### Binary Addition

Binary addition is very simple. Similarly to normal decimal addition, you can just add the numbers together, remembering that binary is a base two system.

$$\begin{array}{r}
1011 \\
+\quad10 \\
\hline
1101
\end{array}$$

### Binary Subtraction

Binary subtraction is slightly harder.

Like normal subtraction, if you want to subtract a $1$ from a $0$ in a digits column, you need to 'borrow' from the next number up.