# Binary Tutorial for Beginners (Free)

## Intro

It is essential for every beginner programmer to have an understanding of how numbers work.

Even before learning programming with a programming language.

Especially binary numbers, because these are central in programming.

So this tutorial aims at a step by step development of a basic understanding of binary numbers.

This tutorial doesn’t assume a lot of knowledge of math, except knowledge of basic calculations.

## Number Systems

To understand binary numbers you have to be familiair with number systems in general.

### Decimal system

The number system we often use without always realising it is the decimal number system.

The decimal number system goes from 0 to 9, which are 10 digits all together.

What happens when you start counting 0, 1, 2, 3… till you reach 9?

9 Becomes 0 and you add a digit of 1 the left and continue counting.

The digit to the left has a higher value than the digit to the right. This refers to the place value.

Every digit in a number has a place value.

For example the number 1573.

Form right to left it contains the digits 3, 7, 5 and 1.

Does the 3 have the same value as the 7 ? Of course not, because the 7 has a higher place value compared to the 3.

We can decompose the number as follows:

1 * 1000 + 5 * 100 + 7 * 10 + 3

If you look closely you can see that the place value increases with a factor of 10, every time you add a digit to the left:

1 * 10 * 10 *10 + 5 * 10 * 10 + 7 * 10 + 3

The factors above can be presented as powers:

1 * 103 + 5 * 102 + 7 * 101 + 3

The 3 also has a factor of 10 and the power of it is 0. A number with a power of 0 is equal to 1:

100 = 1 and not 0!

So a complete representation of the number 1573 in factors and powers is :

1 * 103 + 5 * 102 + 7 * 101 + 3 * 100

It is important to get this notation, because a lot of concepts are build on it.

The above principles may seem very simple. It is necesarry to point these out, because they also apply to the binary system.

### Binary system

With the decimal system we counted from 0 to 9. This is called a base or modulus.

The base of a decimal system is 10, because you can count with 10 digits before you have to add a new place to the left.

The binary system has a base of 2. It only goes from 0 to 1.

So every time you reach 1, you have to add a new place with a digit to the left.

This is exactly as you would do with the decimal system.

1 In decimal is just 1 in binary.

But with 2 in decimal you have to add a digit to the left in binary. So 2 in decimal is 10 in binary.

Below is a table with the decimal values 0 to 9 mapped to the same value in binary.

As you can see above, you need more digits in binary to represent a value.

A single binary digit is called a bit.

You already need 4 bits for a value of 9!

Some other names:

• 4 Bits are called a nibble
• 8 Bits form a byte

Now you know that the base of a binary number system is 2, and every digit in a number has a place value.

The place value is just expressed as a power of the base.

To illustrate this we take the binary value of 1001 and decompose it:

1 * 23 + 0 * 22 + 0 * 21 + 1 * 20

As you can see, it is exactly as the notation we applied earlier.

The only difference is the base, which is now 2 instead of 10.

When you add everything up, you get the decimal value of 9.