I stopped my previous article with a promise that I would show you more about how to represent music, picture, and video and how to store them in computer memory. But when we climb a ladder, we need to step one at a time without any skip to get to the top safely; skipping one means gambling to fall. So, let’s make things simple and easy, and climb the ladder one step at a time together.
Types of Number systems
When we talk about number systems, we talk about two types of number systems.
Non-Positional Number Systems
This kind of number system that doesn’t require a small set of symbols, and the symbol’s value differs based on the position it will be. Instead, these number systems need different symbols/characters to represent different values. The perfect examples of these categories are the Roman and Geez number systems.
To make things clear, let’s see it in action by example. The symbol V in Roman numbers means 5, and XVII means 17. Based on this example, the position of V tell us nothing about its value. This reason makes arithmetic computation so hard to perform on a Non-positional number system.
Positional Number Systems
These systems use a small set of symbols to represent a value, and the symbol’s value will change according to the position it sits on. I will elaborate on it with an example while discussing positional number system types.
Positional number systems are further divided into:
- Decimal: called base or radix 10 because it uses 10 symbols; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
- Binary: called base or radix 2 because it uses only 2 symbols, meaning 0, 1
- Octal: called base or radix 8 because it uses 8 symbols, meaning: 0, 1, 2, 3, 4, 5, 6, 7
- Hexa-Decimal: called base or radix 16 because it uses 16 symbols, meaning: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F (either small or capital letter, it doesn’t matter)
In the Hexa-Decimal number system, A represents 10, and F means 15. It’s just a way of expressing combination of two symobl values using one single symbol. So, A - F means, in other words, 10 - 15.
Why Positioning?
Now, let’s see how the position of a symbol affects its value by taking an example. Let’s take 555 as an example in decimal, i.e., with the base 10. Careful here; we used only one symbol, 5, but we are talking in tens and hundreds. What affects its value? The answer is its position. How? Like this:
555 = (5 * 100) + (5 * 10) + 5
So far, so good, right? But wait, from where did 100 and 10 come? To answer that, let’s assign a positional number to each symbol of 5 from right to left, starting from 0. Let’s use a table to make things simple:
Positions | 2 | 1 | 0 |
---|---|---|---|
Digits/Symbols | 5 | 5 | 5 |
Now, let’s raise 10 by the power of the positions, like so:
Positions | 2 | 1 | 0 |
---|---|---|---|
Digits/Symbols | 5 | 5 | 5 |
10 raised to the power of positions | 102 | 101 | 100 |
From grade 4 or 5 Maths, we all knew any number raised to the power of 0 is 1. Based on this concept, let’s rewrite the above table like so:
Positions | 2 | 1 | 0 |
---|---|---|---|
Digits/Symbols | 5 | 5 | 5 |
10 raised to the power of positions | 102 | 101 | 100 |
Power results | 100 | 10 | 1 |
Thus the above table let us have the following result:
(5 * 100) + (5 * 10) + (5 * 1) = 555
Simple, right? This same thing works for all the Positional Number system types.
But the question is, since computers are only aware of Binary number systems, is there a mechanism we can convert one positional number system to another? The answer is yes. Let’s see how to do it next.
Conversion between Number systems
By the way, to signify what number system we are using, we use subscript notations like (276)10, i.e., we are using a decimal number system.
Binary to Decimal
(10110)2 = (1 × 24) + (0 × 23) + (1 × 22) + (1 × 21) + (0 × 20) = (22)10
How? The technique is the same as mentioned above. Go ahead and check it out by yourself.
Octal to Decimal
(673)8 = (6 × 82) + (7 × 81) + (3 × 80) = (443)10
Again the same technique.
Hexadecimal to Decimal
reminder
A in hexadecimal means 10 in decimal, B in hexadecimal equals to 11, and it continues till F which is equals to 15 in decimal.
(A42)16 = (10 × 162) + (4 × 161) + (2 × 160) = (2626)10
The same technique goes here as well.
Decimal to Binary
Here comes the tricky part, here the technique is to divide the number by two, record the remainder, and keep doing it until you reach zero. To get the correct answer, rearrange your remainders from the last to the first one.
(75)10 = (1001011)2
How?
Division by 2 | Quotient | The remainder (Digit) | Bit Position |
---|---|---|---|
(75)/2 | 37 | 1 | 0 |
(37)/2 | 18 | 1 | 1 |
(18)/2 | 9 | 0 | 2 |
(9)/2 | 4 | 1 | 3 |
(4)/2 | 2 | 0 | 4 |
(2)/2 | 1 | 0 | 5 |
(1)/2 | 0 | 1 | 6 |
Then when we rearrange the values using their bit position, we will get (1001011)2
Octal to Binary
Here there is no direct way. We use the indirect conversion method, i.e., we will represent each octal symbol by 3 position binary number even if we don’t necessarily need 3 positions. Then, why 3 places? Because the maximum number of binary positions we need for the maximum number of octal is 3, that’s the standard mechanism to represent all octal symbols. In addition, adding 0 in front of any number won’t affect its value.
We need the following table to convert Octal to Binary.
Octal Symbol | Actual Binary Value | Octal Representation |
---|---|---|
0 | 0 | 000 |
1 | 1 | 001 |
2 | 10 | 010 |
3 | 11 | 011 |
4 | 100 | 100 |
5 | 101 | 101 |
6 | 110 | 110 |
7 | 111 | 111 |
(154)8 = (1101100)2 How? Let’s use our friendly table above and elaborate. First, let’s put each digit of octal numbers in separate boxes:
Octal Number | 154 | ||
---|---|---|---|
Individual Digits | 1 | 5 | 4 |
Then let’s copy their value from the above table:
Octal Number | 154 | ||
---|---|---|---|
Individual Digits | 1 | 5 | 4 |
Individual Binary Values | 001 | 101 | 100 |
Then let’s put all of the binary numbers together.
Octal Number | 154 | ||
---|---|---|---|
Individual Digits | 1 | 5 | 4 |
Individual Binary Values | 001 | 101 | 100 |
Final Binary Value | 1101100 |
Is that confusing? Do it over and over again, and it will definitely get easier.
Hexadecimal to Binary
We use the same technique as we used for octal numbers. Here, instead of 3 positions, we use 4 positions because the last number of Hexadecimal, F (15), needs 4 positions of binary number representation.
Let’s define the table we need to convert Hexa to Binary.
Hexadecimal | Actual Binary Value | Hexadecimal Binary Representation |
---|---|---|
0 | 0 | 0000 |
1 | 1 | 0001 |
2 | 10 | 0010 |
3 | 11 | 0011 |
4 | 100 | 0100 |
5 | 101 | 0101 |
6 | 110 | 0110 |
7 | 111 | 0111 |
8 | 1000 | 1000 |
9 | 1001 | 1001 |
A | 1010 | 1010 |
B | 1011 | 1011 |
C | 1100 | 1100 |
D | 1101 | 1101 |
E | 1110 | 1110 |
F | 1111 | 1111 |
Example:
(102A)16 = (1000000101010)2
How? Let’s repeat what we did for the octal numbers. First, let’s put each digit of octal numbers in separate boxes:
Hexa Number | 102A | |||
---|---|---|---|---|
Individual Digits | 1 | 0 | 2 | A |
Then let’s copy their value from the above table:
Hexa Number | 102A | |||
---|---|---|---|---|
Individual Digits | 1 | 0 | 2 | A |
Individual Binary Values | 0001 | 0000 | 0010 | 1010 |
Then let’s put all of the binary numbers together.
Hexa Number | 102A | |||
---|---|---|---|---|
Individual Digits | 1 | 0 | 2 | A |
Individual Binary Values | 0001 | 0000 | 0010 | 1010 |
Final Binary Value | 1000000101010 |
It’s getting easier, right?
Note: We can convert Hexa Decimals and Octals using a different technique. The technique is; first, we convert them to Binary using above mentioned techniques and then convert Binarys to Decimals but it’s tedious. The choice is yours.
Let’s try to summarize and put the conversion methods we have seen in one table.
Conversion between Number systems Summary
From Base | To Base | Method/s |
---|---|---|
2 | 10 | Expand binary number in powers of 2 |
10 | 2 | Factor the decimal number by 2 |
2 | 8 | Group 3 binary digits together |
8 | 2 | Convert each octal digit to 3 digits binary number |
2 | 16 | Group 4 binary digits together |
16 | 2 | Convert each octal digit to 3 digits binary number |
8 | 10 |
|
10 | 8 | Go from decimal to binary then octal |
8 | 16 | Go from octal to binary then hex |
16 | 8 | Go from hex to binary then octal |
16 | 10 |
|
10 | 16 | Go from decimal to binary then hex |
I know we socked up a lot of information at once but it’s worth it, right?
In general, number systems look like this from start to finish. In my next article as I promised you before I will talk about Data Representation in computers in detail. Till then stay tuned! And don’t forget to exercise what you have learned today.