The binary numeral system or base-2 numeral system is a way of writing numbers using only two digits, 0 and 1. Each digit is referred to as a bit (binary digit). These two digits are enough to represent any number. How is it possible? Let's find out.
Decimal vs Binary
In everyday life we use the decimal number system, or, simply put, we have 10 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). We don't think about it, but every number is represented as 1 one of the digits + 10 one of the digits + 100 one of the digits etc. (that is, every power of 10 multiplied by some digit).
Let's look at a number in the decimal system, for example, 4251. It is:
So when we read this number, we just look at each digit starting from the last and multiply each digit by its corresponding power of 10: the rightmost is always 1, then goes 10, 100, 1000, and so on.
In the binary number system, we do exactly the same, except the base is 2, not 10. Let's look at a number in the binary system, for example, 1011.
Binary counting
In the decimal numerical system, we have exactly 10 digits (from 0 to 9) to represent any number. And you know how to count in decimal: 0, 1, 2, ..., 9, 10, 11, ..., 19, 20, and so on.
But how to count in the binary system? The table below shows it.
|
Decimal |
Binary |
Powers of two |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
To understand why 5 equals to 101 in binary format, let's write the number in powers of two: . Look at the coefficients closely, they exactly match the binary representation: 101.
As you can see, we start from 0 as before, then comes 1, and then 10. So, binary counting goes like this: when a digit reaches 1, the next number resets this digit to 0 and causes the digit to the left to raise. After some practice, it should become more clear.
Zero padding
Occasionally you will need to work with binary numbers of a fixed length. To achieve this, you can add insignificant zeros to any binary number on the left side, for example, 11 → 0011, 101 → 0101. This operation does not change the number but allows you to format them.
You might come across the following formats:
-
triads: 000, 001, 010, and so on;
-
tetrads: 0110, 0111, and so on;
-
8-digit numbers: 00000000, 01010101, and so on.
Why & where
Almost all modern digital devices use the binary number system. The reason for this lies in the hardware. Computers started using the electronic tubes or relays and then transistors, all of which could be used to represent two states and quickly change from one to the other.
Even the computer memory is binary: we either have something in the memory cell or not. It is conventional to group information in 8-digit binary numbers, where each 8-digit number is referred to as a byte. An 8-digit binary number may represent each of 256 possible values from 0 to 255, and can therefore be used for storing a wide variety of data. Such a way of storing information is called the binary code and is used almost everywhere.
A good example of a binary code, an English text is usually encoded with ASCII (American Standard Code for Information Interchange) code, where each character in the text string was originally represented by a 7-digit binary number (lowercase a is 1100001, and so on…). Later, ASCII was modified and now it uses 8 bits.
Colors can also be encoded that way. The RGB (stands for Red, Green, Blue) color encoding system stores 3 binary values, 1 binary number for each color, representing the saturation of red, green, and blue color components respectively. The (11111111, 00000000, 00000000) color, for example, is pure red, with no shade of green or blue.
In fact, everything can be (and is) encoded using the binary code.