DEV Community

Cover image for Binary Numbers | Tatev Beglaryan | INTRO TO CS
Tatev Beglaryan
Tatev Beglaryan

Posted on

Binary Numbers | Tatev Beglaryan | INTRO TO CS

Hello everyone!

In this post, we'll cover binary numbers, how to convert between different number systems

Binary Numbers & Beyond
A Journey Through Number Representations

In the world of computing, numbers are more than just a way to count—they are a language that allows humans to communicate with machines. The most familiar number system is the decimal (or base-10) system, the one we use in everyday life, which includes digits 0 through 9. However, there are other systems that play an integral role in computing, such as binary (base-2), hexadecimal (base-16), and octal (base-8). Let's dive into the fascinating world of number representations, conversions, and operations in these different bases.

The Binary System: The Language of Computers
At the heart of every computer is the binary system, consisting of only two digits:0 and 1. These digits correspond directly to the on and off states of transistors within a computer’s processor. A 1 represents a signal (or "on"), while a 0 represents no signal (or "off"). Despite its simplicity, this system is powerful enough to run every program you’ve ever used.

Converting Decimal to Binary
Let’s start with a simple conversion: turning a decimal number into binary. The process involves repeated division by 2, keeping track of the remainder at each step. When the quotient reaches zero, the sequence of remainders, written in reverse order, forms the binary number.

For example, let’s convert 450 to binary:

450 ÷ 2 = 225, remainder: 0  
225 ÷ 2 = 112, remainder: 1  
112 ÷ 2 =  56, remainder: 0  
 56 ÷ 2 =  28, remainder: 0  
 28 ÷ 2 =  14, remainder: 0  
 14 ÷ 2 =   7, remainder: 0  
  7 ÷ 2 =   3, remainder: 1  
  3 ÷ 2 =   1, remainder: 1  
  1 ÷ 2 =   0, remainder: 1  
Enter fullscreen mode Exit fullscreen mode

Writing the remainders in reverse order gives us 111000010. Therefore, 450(base10) is equal to 111000010(base2).

Converting Binary to Decimal
To convert a binary number back into decimal, you multiply each binary digit (from right to left) by powers of 2. Let’s use the binary number 111000010 (from the previous step) to convert it back to decimal:

(1 * 2^8) + (1 * 2^7) + (1 * 2^6) + (0 * 2^5) + (0 * 2^4) + (0 * 2^3) + (0 * 2^2) + (1 * 2^1) + (0 * 2^0)
= 256 + 128 + 64 + 0 + 0 + 0 + 0 + 2 + 0 = 450

Enter fullscreen mode Exit fullscreen mode

So, 111000010(base2) equals 450(base10). Our conversion was spot-on!

Exploring Other Number Systems: Octal and Hexadecimal
Other useful number systems include octal (base-8) and hexadecimal (base-16). Each of these is directly related to binary and can be easily converted from it.

Binary to Octal
To convert binary to octal, group the binary digits into sets of 3 (starting from the right). Each group is then converted to its octal equivalent.
_
For example, let’s convert 111000010(base2) to octal:_

111 000 010
(7) (0) (2)

Enter fullscreen mode Exit fullscreen mode

Thus, 111000010(base2) is 702(base8).

Binary to Hexadecimal
Similarly, to convert binary to hexadecimal, group the binary digits into sets of 4 and convert each group to its hexadecimal counterpart.

Thank you, and I hope this was helpful!

Top comments (0)