DEV Community

Davit Avagyan
Davit Avagyan

Posted on

Binary Numbers and Other Numbers Representations: Understanding How Computers Think

the numbers system we use in our daily life is called a decimal system (base 10), but when we deal with computers things are different. Today we will talk about the binary system (base 2) and another system that is used in the programing called the octal system (base 8). We’ll explore these number systems, how they relate to each other, and how to convert between them.

The Decimal System (Base 10)

The decimal system is the system that we humans use in our daily life, based on 10 digits: from 0 to 9. Each digit represents a power of 10 for example the number 852 can be represented as:

852=8102+5101+2100 852 = 8*10^2 + 5*10^1 + 2*10^0

Here, the position of each digit tells us how many powers of 10 it represents.

The Binary System (base 2)
Binary is the system that computers use. Computers are built from transistors which are tiny switches that can either be on which means that ellectricity flaws through them, or off which means that it doesn’t. When the transistor is off it is represented by the digit 0, and when it is on we write 1. So the binary system has only 2 digits that are 0 and 1. Each binary digit represents a power of 2. lets break down the binary number 1101:

1101=123+122+021+120 1101 = 1*2^3 + 1*2^2 + 0*2^1 + 1*2^0

when we calculate the values this equals:

1101=8+4+0+1=13

so the binary number 1101 is equivalent to 13 in decimal representation.

Converting Decimal to Binary

Converting a decimal number to binary involves repeatedly dividing the number by 2 and recording the remainders. Here’s how to convert 45 to binary:

Divide 45 by 2 → quotient = 22, remainder = 1
Divide 22 by 2 → quotient = 11, remainder = 0
Divide 11 by 2 → quotient = 5, remainder = 1
Divide 5 by 2 → quotient = 2, remainder = 1
Divide 2 by 2 → quotient = 1, remainder = 0
Divide 1 by 2 → quotient = 0, remainder = 1

Now, read the remainders from bottom to top: 101101. So, 45 in decimal is 101101 in binary.

The Octal System (Base 8)
the Octal system uses the digits from 0 to 7, and each position represents a power of 8. While this system is not as commonly used as the binary system, it has its applications, particularly in computer systems where binary digits are grouped in sets of 3.

Converting Binary to Octal

Since 8 = 2*2*2, converting binary to octal is pretty simple. We just need to group the digits into groups of 3 starting from the right and then convert each group to its octal equivalent.

For example, converting 110101 (binary) to octal:

Group the digits: 110 and 101.
Convert each group to decimal:

110=6
101=5

So, the octal representation is 65.

Top comments (0)