# Binary

Let’s learn about the binary number system.

We'll cover the following

## Writing a number in binary

Binary numbers are numbers written in base 2. Binary numbers follow very similar rules to decimal numbers. In fact, the only real change is that the role of the number 10 in writing a decimal number is replaced by the number 2. Thus, the new rules are:

1. The digits of a binary number can take the value 0 or 1.

2. Every digit in a binary number can be multiplied by some power of 2. The powers of 2 start with 0 (the furthest digit to the right) and then increase from right to left.

Consider the binary number $1101_2$ (We have used the subscript 2 to make it clear that we mean the number 1101 in binary and not the decimal number one thousand one hundred and one, which we would have written as $1101_{10}$). Using the rules given above (and comparing them with the explanation of decimal numbers), we see that each binary number is a sum of multiples of powers of 2:

$1101_2 = (1 \times 2^3 ) + (1 \times 2^2 ) + (0 \times 2^1 ) + (1 \times 2^0)$

Similarly, the number $110010_2$ is the sum of multiples of powers of 2 expressed by:

$110010_2 = (1 \times 2^5 ) + (1 \times 2^4 ) + (0 \times 2^3 ) + (0 \times 2^2 ) + (1 \times 2^1 ) + (0 \times 2^0)$

Every binary number has a decimal equivalent, and every decimal number has a binary equivalent. In the next section, we’ll explain how to convert from one to the other.

## Converting binary to decimal

Converting binary to decimal is easy. Simply express the binary number as its sum of multiples of powers of 2, and then add them up. So, what is 11012 in decimal? We know that:

$1101_2 = (1 \times 2^3 ) + (1 \times 2^2 ) + (0 \times 2^1 ) + (1 \times 2^0)$

$= (1 \times 8) + (1 \times 4) + (0 \times 2) + (1 \times 1)$

$=8+4+0+1 = 13$

So what we are saying is that the number 1101 in binary is the same as the number 13 in decimal, or in other words, $1101_2 = 13_{10}$.

Here, we have a coded example of the binary to decimal conversion defined above:

Get hands-on with 1200+ tech skills courses.