Let's start from the point where we've left in the previous slide.
I previously said that Octal and Hexadecimal are useful to represent very large number, when binary number system fails to represent those in an efficient way.
First we will discuss about Octal Number System.
Octal Number System
I have already given you the advantage of octal number system. Now let's look, what the octal number system actually is?.
Octal means 8 (just like binary means 2 and decimal means 10). It means that in octal number system we have 8 distinct value i.e. 0,1,2,3,4,5,6,7.
Ok, now we know advantage of octal system and what distinct values it contains. Now, let's see how we utilize that advantage which it has over the binary number system.
|
Octal and Binary Comparison.
|
Converting Binary to Octal number:
You can clearly see that where we require 3 bits in binary form we can represent that number easily in 1 bit of octal form. Now you might be thinking that if the number of bits is greater than 3 like in case of 65 we were having 1000001 then what should we do.
The conversion from binary to octal is very easy you have to make pairs from binary digits where each pair contains 3 binary digits, from right to left, and if there are less number of digits on the left side then add successive zeroes to the left.
like after pairing binary representation of 65 we get following pairs (001)(000)(001). Now simply look at the table above (remembering it will be better too) and write down it's octal equivalent i.e.
(001)(000)(001) in binary is equivalent to 101 in octal.
Isn't this damn easy.
Converting Octal to Binary number:
Ok, now lets see how we can convert an octal number to its binary equivalent.
It's more simpler than converting binary to octal, we just have to write the three digit equivalent of binary in place of every digit of octal number take 101 we calculated above just replace every digit by its 3 digit binary equivalent and you will get your answer.
Converting Decimal to Octal number:
We can convert Decimal to octal by first converting decimal to binary than binary to octal. But, If you don't want to do this in two steps You can use double dabble method but the only change is we repeatedly divide the decimal number with 8 instead of 2, others steps are same as decimal to binary conversion.
Converting Octal to Decimal number:
This task is also fairly easy perform the same procedure like we did in converting binary to decimal system but replace the weights of the ith digits from 2^i to 8^i or 2^(i-1) to 8^(i-1). It's as simple as that.
Now we are done with octal number system, But, If anyone wants to learn Octal arithmetic do let me know in the comment section. I will make a separate post on that.
Hexadecimal Number System
I have talked little bit about hexadecimal number systems in the previous post and in this post also, but in this section let's clear the concepts with sandpaper😳.
Hexadecimal means 16, which simply means that there are 16 distinct values in hexadecimal, but one might be thinking that if we have 0 - 15 numbers than how can we think of this number 115, Is this number 1 and 15 or 11 and 5 or 1 and 1 and 5 whatever the confusion maybe there. But, that's where our intelligent researchers play their roles. and they didn't assigned the number from 0-15 rather they used digits from 0-9 and English alphabets A-F (Researchers are COOl AF).
Now, some of us would ask (assuming so 😬) that why there is not any number system used with radix(base) 32, then it would be easy to represent even more large numbers with just small number of bits. You should read these answers.
Let me write the whole list for your reference.
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.
(sorry, but if you haven't noticed there must be 0 and 0000 too in this table.)
|
Hexadecimal and Binary Comparison. |
Converting Binary to Octal number:
You can clearly see that where we require 4 bits in binary form we can represent that number easily in 1 bit of hexadecimal form. Now you might be thinking that if the number of bits is greater than 4 like in case of 65 we were having 1000001 then what should we do.
The conversion from binary to octal is very easy you have to make pairs from binary digits where each pair contains 4 bits, from right to left, and if there are less number of digits on the left side then add successive zeroes to the left.
like after pairing binary representation of 65 we get following pairs (0100)(0001). Now simply look at the table above (remembering it will be better too) and write down it's octal equivalent i.e.
(0100)(0001) in binary is equivalent to 41.
Converting Octal to Binary number:
Ok, now lets see how we can convert a hexadecimal number to its binary equivalent.
It's more simpler than converting binary to octal, we just have to write the three digit equivalent of binary in place of every digit of octal number take 41 we calculated above just replace every digit by its 4 digit binary equivalent and you will get your answer.
Converting Decimal to Octal number:
We can convert Decimal to hexadecimal by first converting decimal to binary than binary to hexadecimal. But, If you don't want to do this in two steps You can use double dabble method but the only change is we repeatedly divide the decimal number with 16 instead of 2, others steps are same as decimal to binary conversion. ( Important note - avoid doing mistakes of writing 10 for ten etc due the reasons I gave you before.)
Converting Octal to Decimal number:
This task is also fairly easy perform the same procedure like we did in converting binary to decimal system but replace the weights of the ith digits from 2^i to 16^i or 2^(i-1) to 16^(i-1). It's as simple as that.
Now we are done with hexadecimal number system, But, If anyone wants to learn hexadecimal arithmetic do let me know in the comment section. I will make a separate post on that.
Click the Subscribe button at the top, to follow my every post regarding c++.
References -
- Wikipedia.
- GeeksForGeeks.
- Lippman, Stanley B. c++ primer 3rd edition(april 2, 1998).
- quora.
Comments
Post a Comment