This is a great example of a computing problem solved using math. And its widely used to represent negative numbers in binary.

In essence, its a way to implement subtraction using addition. Why? Because digital circuits for addition are very simple.

Bits and Bytes

A bit is a thing that can be in one of two states, on or off, $1$ or $0$.

A byte is a sequence of $8$ bits. So how many states can it be in? $2$ states for each bit, so $2\times 8$. This seems like a reasonable argument but it's incorrect because it ignores a crucial part of the definition, the sequence.

For simplicity, lets first try figuring out the number of states of a sequence of $4$ bits. I will call the bit in brackets the extra bit.

$$ \{0\}000 $$

Excluding the extra bit, in how many states can the remaining sequence of $3$ bits be.

$$ \begin{matrix} 100\\011 \\ 110\\001 \\ 101\\010 \\ 111\\000 \end{matrix} $$

Listing them out, there are $8$ states.

Adding the extra bit, the possible states are

$$ \begin{matrix} \{1\}100\\\{1\}011\\\{1\}110\\\{1\}001\\\{1\}101\\\{1\}010\\\{1\}111\\\{1\}000\\ \end{matrix}

\\begin{matrix}
\\{0\\}100\\\\\\{0\\}011\\\\\\{0\\}110\\\\\\{0\\}001\\\\\\{0\\}101\\\\\\{0\\}010\\\\\\{0\\}111\\\\\\{0\\}000\\\\
\\end{matrix}
$$

Notice how the states nicely divide into two groups. The number of states in each of these groups is the same as the number of states of a sequence of $3$. This is true because for each group, the extra bit is not changing. Because its the same for all states in a group, it cannot create any new state.

So adding an extra bit doubles the number of states.

Using this result, we can calculate the states of a byte. Lets first consider one bit. It has two states. Adding a bit would double the states. So a sequence of two bits has $4$ states. Adding a bit to this sequence of $2$ bits would make the number of states $8$. Adding a bit to this sequence of $3$ bits would make the number of states $16$. So for every bit we add, we have to multiply the number of states by two.

Hence, for adding $7$ bits to one bit, we will have to multiply the number of states by $2$ seven time. This makes the number of states $(\\text{Number of states of a bit})\\times2\\times2\\times2\\times2\\times2\\times2\\times2=2\\times2^7=2^8$

**All binary numbers are represented with $8$ digits.**

### Unsigned Integers

For an unsigned integer, each of the 256 states represents an integer from $*0*$ to $*255*$(including $0$). From $*0000~0000*$ to $1111~1111$.

Just like $9999=9\\times10^3+9\\times10^2+9\\times10+9$, there is a specific way of interpreting unsigned integers represented by bytes.