DEV Community

Tsolak Shahbazyan
Tsolak Shahbazyan

Posted on

- binary numbers, other number representations - conversions between different number representations

Understanding Binary Numbers and Other Number Representations.

Most of us are familiar with the decimal system, but computers and various fields of science rely on other number systems, such as binary, octal, and hexadecimal. Let's break these down into something easy to understand and explore how to convert between them.


Decimal System (Base 10)
The decimal system is what we use in everyday life. It's a base-10 system, meaning it has 10 digits: Currently it's the most convinient one, because we humans , have 10 fingers on our hands aand are naturally used to counting by them: 0 through 9. Each digit in a number represents a power of 10, depending on its position. For example, the number 345 in decimal can be broken down as:

3×10^2 +4×10^1 +5×10^0 =300+40+5


Binary System (Base 2)
The binary system is the language of computers, which uses only two digits: 0 and 1. These are called bits. Like the decimal system, the binary system uses positional notation, but instead of powers of 10, it uses powers of 2.

For example, the binary number 1101 can be wrotten down like this:
1×2 ^3 +1×2^2 +0×2^1 +1×2^0=8+4+0+1=13 (in decimal)


Hexadecimal System (Base 16)
The hexadecimal system (or hex) is a base-16 system using 16 digits: 0-9 and A-F, where A represents 10, B is 11, and so on up to F, which is 15. It's often used in computing because it's more compact than binary but easily converts to and from it.

For example, the hex number 1F is converted like this:
1×16^1+F×16^0 =16+15=31 (in decimal)


Converting Between Number Systems

Decimal to Binary
Let’s convert the decimal number 23 to binary. The method is simple: divide the number by 2 and write the remainder. Repeat the process with the quotient until you reach 0. The remainders gives the binary digits,
which we have to read from bottom to top.

Here’s how it works for 23:

23÷2=11
 remainder 1
11÷2=5
 remainder 1
5÷2=2
 remainder 1
2÷2=1
 remainder 0
1÷2=0
 remainder 1

Reading the remainders from bottom to top gives 10111 in binary.
Binary to Decimal

Now, to convert 10111 back to decimal, use the powers of 2, as shown earlier:

1×2^4 +0×2^3 +1×2^2 +1×2^1 +1×2^0=16+0+4+2+1=23


Decimal to Hexadecimal
To convert decimal to hexadecimal, divide by 16 and write the remainders in a similar way. For instance, converting 31 to hex:

31÷16=1
 remainder 15
15
1÷16=0
 remainder 1

Reading from bottom to top, we get 1F, because in hexadecimal, f is the 15.


Top comments (0)