Number Systems — In a Nutshell

Piyush Kochhar
7 min readJul 28, 2020

--

Number Systems — Created by Piyush Kochhar

Number system is just a way to represent numbers. We need such systems because these are the numbers that the computer understands. So, let’s dive into it.

Decimal Number System

You’ve used it. That’s’ one less thing to learn.

In our everyday lives, we use decimal system. Buy groceries, you get a receipt of $120.20. That’s in decimal number system. And lucky for us computer already understands it.

So, what’s the catch. Just that it’s not the only number system computer understands we need other systems as well to make sense of everything and we’ll also discuss where they are used.

Convert Decimal Number System

Binary Number System

As the name suggests binary means 2. So, we use 2 numbers (0’s & 1’s) to represent any number.

Eg: (10) base 10 => 1010 base 2

Ahem base? It just tells us what number system we are using to represent a number. In the above e.g. 10 is in decimal system and its equivalent binary is 1010.

Why use Binary? The binary system is mostly used because computers store their information in binary. All data, including the numbers and instructions are represented as 0 and 1 in the machine. Microprocessor also use binary system to perform some basic operations.

Convert Binary to Decimal:

E.g. 1101 base 2 => (?)base 10

Pro Tip: To convert any number system to decimal just multiply each digit in the problem with (base) power (number place), number place is just the place of a number. Digit on far right before decimal point will have a number place of 0 and digit on far left will have number place of (total digits -1).

Number and Number Place

Number = 1 1 0 1

Number Place = 3 2 1 0

Here is what it means.

N = 4 = 1101 has 4 digits

And we calculate value for each digit with base ^ (number place).

In the example that would be:

(1*(2³) + 1*(2²) + 0*(2¹) + 1*(2⁰)) => (8 + 4 + 0 + 1) => (13) base 10

Tada!

Another Example: -> (11110100.01) base 2 => (?) base 10

Every digit after decimal point has a negative number place. So 1st digit after decimal point has a no place of -1, 2nd decimal digit has no. place of -2 and so on.

=> (1*(2⁷) + 1*(2⁶) +1*(2⁵) +1*(2⁴) +0*(2³) +1*(2²) +0*(2¹) +0*(2⁰) + 0*(2^-1) +1*(2^-2)) = (244.25) base 10

Easy peasy lemon squeezy!

Convert Decimal to Binary:

It’s the opposite what we did above. Here we divide and keep track of the remainder. Read the remainders from bottom to top and that’s your solution.

Eg: (224) base 10 => (?) base 2

So, our solution is: (11110100) base 2

Shortcut Method:

Keep dividing the number by 2 until you get 1. Mark each even number as 0 and odd as 1.

For same number 244, we can solve it like:

Keep the original no. to the right, and start dividing on the left by 2

=> (11110100) base 10

Remember mark even as 0 and odd as 1.

Octal Number System

Octal means 8, therefore valid numbers in octal system are 0 to 7.

Why use octal? It is used to perform bit manipulation operations needed for systems programming (e.g. Left shift, right shift) i.e. used in Low- level programming. It uses only 3 bits to represent any binary no and therefore has fewer operations.

Convert Octal to Decimal:

(12.2) base 8 => (?) base 10

It’s similar to decimal to binary conversion. Use 8 instead of 2.

(1*(8¹) + 2*(8⁰) + 2*(8^ )) => (8 + 2 + 0.25) => (10.25) base 10

Convert Octal to Binary:

(12) base 8 => (?) base 2

1st method: Convert octal to decimal and then to binary

(12) base 8 => (10) base 10 => (1010) base 2

Shortcut Method:Split each digit of base 8 number and convert it into its 3 bit binary equivalent.

e.g. (127) base 8 => (?) base 2

1 => (001) base 2 and 2 => (010) base 2 and 7 => (111) base 2

Just concatenate the solutions => 001 010 111 => (1010111) base 2

Convert Binary to Octal:

Shortcut Method: Do the opposite of octal to binary conversion. Instead of dividing an octal digit into 3bit pairs we combine 3 bit pairs to form an octal digit.

(10101) base 2 => (?) base 8

Start forming 3 bit pairs from the far right. We get 2 pairs 10 and 101. To make each pair 3 bit just pad 0’s in front of the number. Therefore, we get: (010) base 2 and (101) base 2

Now, just convert these numbers into their decimal equivalent to get an octal digit.

(010) base 2 => (2) base 10 and (101) base 2 => (5) base 10

Upon concatenation, we get: (25) base 8

Convert Decimal to Octal:

1st Method: Divide the number by 8 and keep track of remainder. Stop division when the quotient is less than 8.

e.g. (127) base 10 to (?) base 8

So, our solution is: (177) base 8

2nd Method: Convert decimal to binary and make 3 bit pairs.

(127) base 10 => (1111111) base 2

=> (001 111 111) base2 => (177) base 10

Hexadecimal Number System

It is a number system that has 16 possible values for each digit. (0–9) and A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.

Why use Hexadecimal? It closely resembles the decimal number system but has an advantage of storing more information in fewer bits. Like (10) base 10 takes 2 bits but in hexadecimal (A) base 16 only takes 1 bit.

Convert Hexadecimal to Decimal:

(0x1F.01B) base 16 => (?) base 10

We can ignore “0x” because it’s just a way to know that the number is in hex.

It’s similar to decimal to binary conversion. Use 16 instead of 2.

(1*(16¹) + F*(16⁰) + 0*(16^-1) + 1*(16^-2) + B*(16^-3))

=> (16 + 15*1 + 0 + 1/256 + 11*1/4096) => (31.00659) base 10

Convert Hexadecimal to Binary:

(0x1A) base 16 => (?) base 2

1st method: Convert hex to decimal and then to binary

(0x1A) base 16 => (26) base 10 => (11010) base 2

Shortcut Method: Split each digit of base 16 number and convert it into its 4-bit binary equivalent.

e.g. (1AF) base 16 => (?) base 2

1 => (0001) base 2 and A => (1010) base 2 and F => (1111) base 2

Just concatenate => 0001 1010 1111 => (110101111) base 2

Convert Hexadecimal to Octal:

Shortcut Method: Convert hex to binary and then to octal.

e.g. (11B) base 16 => (?) base 8

(11B) base 16 => (100011011) base 2

Now make 3 bit pairs and concatenate.

(100 011 011) base 2 => (433) base 8

Convert Binary to Hexadecimal:

e.g. (111000) base 2 to (?) base 16

Shortcut Method: Similar to octal to binary conversion. Only difference is we make 4 bit pairs instead of 3.

(111100) base 2 => (0011 1100) base 2 => (3C) base 16

Convert Octal to Hexadecimal:

Shortcut Method: Convert octal to binary and then to hex.

e.g. (765) base 8 => (?) base 16

(765) base 16 => (0001 1111 0101) base 2 => (1F5) base 16

Convert Decimal to Hexadecimal:

1st Method: Divide the number by 16 and keep track of remainder. Stop division when the quotient is less than 16.

e.g. (456) base 10 to (?) base 16

So, our solution is: (1C8) base 16

2nd Method: Convert decimal to binary and make 4 bit pairs.

(456) base 10 => (111001000) base 2

=> (0001 1100 1000) base2 => (1C8) base 10

--

--