DEV Community

Lia
Lia

Posted on

Binary Numbers: Understanding Number Representations in Computing

Have you ever wondered how computers work? At first sight, it’s like a box with a lot of complicated metal parts inside it. To get around the computer world, you will need to understand binary, which I will explain soon. In a computer, there is a Central Processing Unit, or CPU, which is silicon with billions of microscopic switches called transistors. Depending on the flow of electricity, they can be on or off, like a light bulb, which gives us two states: 1 and 0. A 0 means the switch is off, and a 1 means the switch is on. This special way of talking is called binary. Binary numbers are how computers understand everything.
You know how you count in decimal, right? When you run out of digits from 0 to 9, you start over by adding a new place. When you count to 10, you put a 1 in the tens place and a 0 in the ones place. It’s the same thing in binary. But instead of counting to 9, you only have 0 and 1. Once you hit 1, the next number is 10, except that's one zero, not ten. Counting in binary is like this: 0 1 1011 100 101 110 111 and 1000 because each binary digit has only two values and not ten, and each additional digit represents an increasing power of two rather than an increasing power of 10. This is the binary way of counting.

Image description

The value at one of these switches is called a bit. A group of 8 bits is called a byte and can have 256 different combinations of 0s and 1s. We can now store information by counting in a system called binary.

Now, let’s talk about how to represent decimal numbers in binary and vice versa.

The process of converting between decimal and binary numbers is not that hard once you get the steps. To convert from a decimal number to a binary number, we have to divide the decimal by 2 and record the remainder. This process needs to be repeated until the quotient is 0, and the reminders must be read in reverse order to get the corresponding binary number. For example;

Image description

For converting binary numbers into decimals, we need to multiply each binary digit by its corresponding power of 2 starting from the right digit, which is 2^0. Then, we should sum the results to get the converted decimal number. For example;

Image description

Using these methods, you can easily switch between decimal and binary numbers.

Top comments (0)