Number Representations: Binary, Decimal and Beyond
Published: 2023-09-13 22:58:49

In the world of computer science and mathematics, numbers are the cells of almost everything. Whether you are counting, solving complex problems, or writing code, understanding different number representations is essential. We are going to break down the basics of binary numbers, explore other number representations and learn how to convert them from one to another.

Part 1: Binary Numbers- The Language of Computers

A binary number  system consists of only two digits: 0 and 1. This simplicity is ideal for computers because they rely on electrical switches, which can be in one of the two known states **on(1)** and **off(0)**. Binary is the foundation of all digital information, which makes it elemental in computer science.

**Counting** in binary is simple. It's similar to counting in decimal(our everyday base-10 system), but each position doesn't represent a power of 10, but a **power of 2**.

**0**(decimal)=**0**(binary)
**1**(decimal)=**1**(binary)
**2**(decimal)=**10**(binary)
**3**(decimal)=**11**(binary)
**4**(decimal)=**100**(binary)
**5**(decimal)=**101**(binary)

Part 2: Conversion Between Number Systems

1.Binary to Decimal
To convert a binary number to decimal, multiply each digit starting from the right to the left, by 2 to the power of its position(start from 0) and add all the results. 
For example: convert 1001(binary) to decimal(base 10)
  1       0       0         1
**2^3*1 + 2^2*0 + 2^1*0  +  2^0*1 = 9(decimal)**
So, 1001(base 2)= 9(base 10)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n3b3z5zvqlg0b1sil81j.png)

2. Decimal To Binary
Converting decimal to binary is the inverse process. Divide the decimal number by 2 repeatedly, and write the remainders each time, until quotient becomes 0. Write the remainders from the bottom to the top, which will be the binary representation.
For example: convert 9(decimal) to binary

9/2 = 4 remainder **1**
4/2 = 2 remainder **0**
2/2 = 1 remainder **0**
1/2 = 0 remainder **1**
9(decimal) = 1001(binary)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7f9z08oagu2h59ry8j67.png)

3. Binary to Hexadecimal

Hexadecimal is a base 16 numbering system. While binary uses only 1 and 0 and decimal 0 through 9, hexadecimal extends to 0-9 and then A-F(equivalent to 10-15 in decimal). With this you can represent a larger range of values with fewer digits.

Step 1: Group the  binary digits into sets of four, starting from the right. (2^4 = 16)
Step 2: Convert each **group of four** to its decimal and hexadecimal equivalent.
0000 (binary) = 0 (decimal)
0001 (binary) = 1 (decimal)
0010 (binary) = 2 (decimal)
...
1001 (binary) = 9 (decimal)
**1010** (binary) = **A** (hexadecimal)
**1011** (binary) = **B** (hexadecimal)
**1100** (binary) = **C** (hexadecimal)
**1101** (binary) = **D** (hexadecimal)
**1110** (binary) = **E** (hexadecimal)
**1111** (binary) = **F** (hexadecimal)
Step 3: Write down the hexadecimal equivalent by matching the values.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kdjnf2msp02wq285bw9g.png)

Hexadecimal to Binary
To convert hexadecimal to binary, take each hexadecimal digit and represent it as a four-bit binary number.(do the opposite of the last conversion)Then combine the binary groups.


Understanding binary numbers and their conversions is vital for understanding the foundations of computer science. Similarly, performing arithmetic operations in binary is essential.
So you can follow the link down below and see how to do operations with binary numbers.
(https://youtu.be/_lrmui-iskE?si=lxbjszVp8FhpqSt4)