As you know, computers are using the binary number system to perform all operations. To be more specific, computers use binary digits (bits) - '0's and '1's. A group of 8 binary digits is called a byte. The byte is the fundamental unit of storage in a computer system. Why is the binary system used in computers (by the way, one of the first computers, invented by Charles Babbage in the 19th century used the decimal number system)? Because it is the simplest system that can be implemented in electronics, as it has just tow states - 'on' (1) and 'off' (0).
People are used to count using the decimal (or base ten) number system. We use the numbers between 0 and 9 to perform different types of calculations. A decimal number is composed of units, tens, hundreds, thousands etc. Let's take the number 1637 for an example. We have the following table:
Now, let's introduce our number (1637) in this table:
The number will represent 1 thousand, 6 hundreds, 3 tens and 7 units. As you can see, each column header, from right to left, represents the result of multiplication by 10 of the previous column header, so we have units (1), tens (10), hundreds (100) and thousands (1000).
The binary system is using just '0' and '1', so, any number in the binary system must be represented by a set of '0's and '1's.
Here is a table:
The table is similar to the previous one (representing decimal numbers), but the column headers are representing two at a power. If we take a closer look at the column headers (from right to left), we see 2 as base (as we work in the binary system) and the exponent is x+1 (is incremented by 1 for every next column, from right to left). The table is the same as:
So, if we have a binary number - 1000101, we can insert it in the table, as follows:
The number should also be written in the table from right to left.
For the specified binary number:
- 1 lot of 64
- 0 lots of 32
- 0 lots of 16
- 0 lots of 8
- 1 lot of 4
- 0 lots of 2
- 1 lot of 1
Converting binary numbers to/from decimal numbers
To convert a binary number to decimal, I will use the table shown before:
Let's take the number 11010010101001 as an example and write it into the table (from right to left):
To get the decimal equivalent of the specified binary number, I have to use multiplication;
1 x 8192 + 1 x 4096 + 0 x 2048 + 0 x 1024 + 0 x 512 + 0 x 256 + 1 x 128 + 0 x 64 + 1 x 32 + 0 x 16 + 1 x 8 + 0 x 4 + 0 x 2 + 1 x 1
I will exclude the ones, that are multiplied by 0 (as any number multiplied by 0 is 0) and calculate the final result:
8192 + 4096 + 1024 + 128 + 32 + 8 + 1 = 13481
The decimal equivalent of 11010010101001 is 13481.
As you see, the column header values of the 'slots' with '1's are just added together to get the decimal equivalent.
The same way I will convert a decimal number to a binary one. Suppose I have the number 6280. I have to choose the closest '2 at a X power' to 6280. The closest is 2 at power 12 (4096). Now I fill the well-known table:
I have to write 1 underneath the maximum number, that can be substracted from 6280. This number is 4096.
6280 - 4096 = 2184
I have 2184 left over. The closest number to 2184 is 2048, so I will write 1 underneath 2048.
2184 - 2048 = 136
I have 136 left over. The closest number to 136 is 128, so I will insert 1 underneath 128.
136 - 128 = 8
I have 8 left over, so I will write 1 underneath 8.
All blank (unused) 'slots' are filled with '0's.
The binary representation of 6280 is 1100010001000.
This tutorial showed what is the binary number system, how it's used and how to convert binary numbers to decimal and decimal numbers to binary.