# Numeral Systems Conversion : Binary, Octal, Decimal and Hexadecimal

As a computer programmer, you need to know about the different numeral systems. In your computer works, there will be lots of times that you will be using numeral systems like the binary, hexadecimal and sometimes octal as well. Thus, it would be a great idea to know how to convert numbers from one numeral system to the other. The digits that all 4 numeral systems use are shown below :

Decimal | Binary | Hexadecimal | Octal |

012
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
0110
11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111 10000 |
012
3 4 5 6 7 8 9 A B C D E F 10 |
012
3 4 5 6 7 10 11 12 13 14 15 16 17 20 |

**Convert From Decimal to Other Numeral Systems**

To convert a number from decimal to any other numeral system, we follow a standard procedure. We divide the integer part of a number with the base number of the system at which we want the actual conversion to occur. For instance, to convert a number from decimal to binary(base 2), we divide that number with 2. While we make each division, the remainder of the division is the rightmost digit of the resulting number in binary and the result of the division gets redivided with 2 till we reach the division where the result is 0. If the number has a fractional part, this gets multiplied by two. The integer part of the number after the multiplication is held, will be the leftmost digit of our new fractional number in the binary system, right after the comma. The result of the multiplication of 2 with the fractional part of the number gets substracted of the integer part used for the creation of the fractional number in the binary system. This new number gets multiplied with 2 again and then the previous procedure is executed again and again, till the new fractional number becomes 0. If the new fractional number is periodic, we cut and round the resulting number. This may sound a bit confusing, so these are some example conversions :

**Convert from decimal to binary Χ _{(10)}->**

**Χ**

_{(2)}**Integer**

45_{(10)}->Χ_{(2)}

Div Quotient Remainder Binary Number (Χ)

45 / 2 22 1 **1**

22 / 2 11 0 **0**1

11 / 2 5 1 **1**01

5 / 2 2 1 **1**101

2 / 2 1 0 **0**1101

1 / 2 0 1 **1**01101

45_{(10)}->101101_{(2)}

**Fractional Part
**

0,182_{(10)}->Χ_{(2)}

Div Product Remainder Binary Number (Χ)

0,182 * 2 0,364 0 0,**0**** **

0,364 * 2 0,728 0 0,0**0**

0,728 * 2 1,456 1 0,00**1**

0,456 * 2 0,912 0 0,001**0**

0,912 * 2 1,824 1 0,0010**1**

0,824 * 2 1,648 1 0,00101**1**

0,648 * 2 1,296 1 0,001011**1 **

0,182_{(10)}->0,0010111_{(2) }(After we round and cut the number)

**Convert from decimal to octal Χ _{(10)}**->

**Χ**

_{(8)}**Integer**

45_{(10)}->X_{(8)}

Div Quotient Remainder Octal Number (Χ)

45 / 8 5 5 **5**

5 / 8 0 5 **5**5

45_{(10)}->55_{(8)}

**Fractional Part**

0,182_{(10)}->Χ_{(8)}

Mul Product Integer Binary Number (Χ)

0,182 * 8 1,456 1 0,**1**

0,456 * 8 3,648 3 0,1**3**

0,648 * 8 5,184 5 0,13**5**

0,184 * 8 1,472 1 0,135**1**

0,472 * 8 3,776 3 0,1351**3**

0,776 * 8 6,208 6 0,13513**6 **

0,182_{(10)}->0,135136_{(8) }(After we round and cut the number)

**Convert from decimal to hexadecimal Χ _{(10)}**->

**Χ**

_{(16)}**Integer**

45_{(10)}->X_{(16)}

Div Quotient Remainder Hex Number (Χ)

45 / 16 2 13 **D**** ** (Since 13 decimal is D in hexadecimal)

2 / 16 0 2 **2**D (See the table)

45_{(10)}->2D_{(16)}

**Fractional Number
**

0,182_{(10)}->Χ_{(16)}

Mul Product Integer Binary Number (Χ)

0,182 * 16 2,912 2 0,**2**

0,912 * 16 14,592 14 0,2**Ε**

0,592 * 16 9,472 9 0,2Ε**9**

0,472 * 16 7,552 7 0,2Ε9**7**

0,552 * 16 8,832 8 0,2Ε97**8**

0,832 * 16 13,312 13 0,2Ε978**D**

0,182_{(10)}->0,2E978D_{(16) }(After we round and cut the number)

**2. Convert from other numeral systems to decimal**

Now, in order to do the opposite, we have to do some pretty different steps than the previous ones. At first, we count the number of digits that our number to convert consists of starting from 0 and going from right to left when the number is an integer. However, when the number is decimal, then we count the digits of the number right after the comma, starting from left and going to the right, indexing them starting from -1. So, in order to convert a number from one numeral system to decimal, we multiply each digit with a number that has its base on the numeral system that the number is represented at. For instance, for binary that number is 2 and we raise that number to the index that each digit is at. In the end, we add all the resulting numbers and the result is that number in decimal. Take a look at the examples below to understand it better :

**Convert from binary to decimal Χ _{(2)}**->

**Χ**

_{(10)}101101,0010111_{(2)}->Χ_{(10)}

Index the digits of the number

1^{5}0^{4}1^{3}1^{2}0^{1}1^{0},0^{-1}0^{-2}1^{-3}0^{-4}1^{-5}1^{-6}1^{-7}

Multiply each digit

1 * 2^{5} + 0 * 2^{4} + 1 * 2^{3} + 1 * 2^{2} + 0 * 2^{1} + 1 * 2^{0} + 0 * 2^{-1} + 0 * 2^{-2} + 1 * 2^{-3} + 0 * 2^{-4} + 1 * 2^{-5 }+ 1 * 2^{-6} + 1 * 2^{-7 } =

(β^{-α }= 1/β^{α})

32 + 0 + 8 + 4 + 0 + 1 + 0 + 0 + 0,125 + 0 + 0,03125 + 0,015625 + 0,007813

= 45,179688_{(10)}

**Convert from octal to decimal Χ _{(8)}**->

**Χ**

_{(10)}55,135136_{(8)}->Χ_{(10)}

Index the digits of the number

5^{1}5^{0},1^{-1}3^{-2}5^{-3}1^{-4}3^{-5}6^{-6}

We multiply each digit

5 * 8^{1} + 5 * 8^{0} + 1 * 8^{-1} + 3 * 8^{-2} + 5 * 8^{-3} + 1 * 8^{-4} + 3 * 8^{-5 }+ 6 * 8^{-6} =

40 + 5 + 0,125 + 0,03125 + 0,009766 + 0,000244 + 0,0001 + 0,0000229

= 45,1663829_{(10)}

**Convert from hexadecimal to decimal Χ _{(16)}**->

**Χ**

_{(10)}2D,2E978D_{(16)}->Χ_{(10)}

Index the digits of the number

2^{1}13^{0},2^{-1}14^{-2}9^{-3}7^{-4}8^{-5}13^{-6}

We multiply each digit

2 * 16^{1} + 13 * 16^{0} + 2 * 16^{-1} + 14 * 16^{-2} + 9 * 16^{-3} + 7 * 16^{-4} + 8 * 16^{-5 }+ 13 * 16^{-6} =

32 + 13 + 0,125 + 0,0546875 + 0,00219727 + 0,00010681 + 0,00000762 + 0,00000077

= 45,18199997_{(10)}

Notice that the decimal numbers are not actually the same as their primary values. We have some losses. These losses are due to the rounds and cuts done in the previous results.

**3. Convert from binary to hexadecimal to octal**

As we all now, 2^{3} results to 8 and 2^{4} gives 16. This reality, believe it or not, will help you understand how to convert from binary to octal and hexadecimal and vice versa. As we said before, 2^{3} gives 8, so in order to convert a binary number to octal, we need 3 digits that will represent a digit of the octal number. Therefore, for a hexadecimal number we need 4 digits to represent a hexadecimal digit. For that reason, we convert a binary number to octal, then separate the binary number into triads or quadruples (when hex), starting from right to left when talking about integers and from left to right when it’s about decimals starting from the comma. If there are digits left in the end that do not make a triple or a quadruple, for the hex system we pad with 0 in front of the number. Then, we substitute each three digit number or four digit binary number with a digit that corresponds to octal when it’s triples or hex when its quadruples. In this conversion, you will be helped from the table above. Here are some examples to understand what was said : ^{
}

**Convert from binary to octal**

110101000,101010_{(2)}->X_{(8)}

| 3 | | 3 | | 3 | | 3 | | 3 |

110 101 000 ,101 010

|| || || || ||

\/ \/ \/ \/ \/

6 5 0 , 5 2 (See that in the array 110_{(2)} corresponds to 6_{(8)} )

110101000,101010_{(2)}->650,52_{(8)}

**Convert from binary to hexadecimal**

110101000,101010_{(2)}->X_{(16)}

| 4 | | 4 | | 4 | | 4 | | 4 |

0001 1010 1000 ,1010 1000

|| || || || ||

\/ \/ \/ \/ \/

1 Α 8 , Α 8

110101000_{(2)}->1Α8,Α8_{(16) }

**4. Convert from hexadecimal to octal and binary**

This is the exact reverse procedure than the previous one. As previously, each digit of the octal number corresponds to 3 digits of the binary number and 4 digits of the hexadecimal number. When the appropriate triples or quadruples are not completed, we pad with 0 in front of each number :

**Convert from octal to binary**

650,52_{(8)}->X_{(2)}

6 5 0 , 5 2

|| || || || ||

\/ \/ \/ \/ \/

110 101 000 , 101 010

650,52_{(8)}->110101000,101010_{(2)}

**Convert from hexadecimal to binary**

1Α8,Α8_{(16)}->X_{(2)}

1 Α 8 , Α 8

|| || || || ||

\/ \/ \/ \/ \/

0001 1010 1000 ,1010 1000

*This is a guest post by a good personal friend of mine under the name Black Shadow.*

Hmm..I dont know about these and didn’t tried to know.They had 0′s and 1′s repeating..BUt you made to look easier.

woah.. thanks a lot for this.. ^_^

Hello could I use a few of the insight located on this web site if I produce a website link again to your internet site?

Of course, feel absolutely free to do so.

maybe this is posted for a long time, but it really helped me. thanks a lot^^

@Hiro : You are welcome !

it’s wonderful to read!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

this is much more easier to read and understand than any other guides.. i hope this will help to my exam tommorrow

This makes the number system conversion easier for me to explain to my students. Thankk you very much

Its really excellant and understandable

If not for your writing this topic could be very couoelntvd and oblique.

Thanks A lot

its true but can any body tel me the conversion of floating decimal values into binary or octal or hexadecimal?????????????????????????

Thanks a lot for this valuable post! I have my tomorrow and Till now I was not able to understand this from any book. God bless you mate

@Shiva Singh : I’m glad it helped you, you are welcome

Thanks a lot for this valuable post!

i hope this will help to my exam tommorrow:D

hey ….ds is awsum yar…i never get good marks in number system..but from this i learned number conversion so easily..i love this..god bless u ..n give lotss of knowledge..so that u can share with uss….he he he …m lovin it…:):):)

3. Convert from binary to hexadecimal and octal

NOT

3. Convert from binary to hexadecimal to octal

ALSO

4. Convert from hexadecimal and octal to binary

NOT

4. Convert from hexadecimal to octal and binary

Sorry

4. Convert from binary to hexadecimal and octal

NOT

4. Convert from hexadecimal to octal and binary

please send me:- A3.8(base 16)=?(base 8)

lot of thanks for this . my studies is getting easier

Nice article. Here’s another useful one, which is focues on the implemenetation and provides C# source code: http://www.pvladov.com/2012/05/decimal-to-arbitrary-numeral-system.html

thanks for this ., my study become easier. and my holiday home work is completed.

Nice article. This is basic need to understand the relation between the different number system. How we can convert this number system to other number system.

You can learn programming version of number conversion here.

what is the decimal conversion of this binary number- 0b10010100

It is very very easy to understand from any book or other guide

i think there’s a mistake in converting 5hex to binary, it’s supposed to be 101 not 100, pls confirm

@nestark, you must mean the 110 in the octal to hex conversion right ? It was a mistake indeed, fixed it, thanx

THANKS !!

Thank You for this…..it really help me.

how can explain this…the decimal=320+binary=10111011+octal=760+hexadecimal=AC0=________16?

2) decimal=1500+hexadecimal=800+binary=1111100+octal= ? =hexadecimal=4,096

3) decimal=(2000/5+hexadecimal=182+decimal=416+binary=11100=_________8

hope you can help me…please =)

i hope you can help me to answer and explain this..

320(base10)+10111011(base2)+760(base8)+AC0(base16)=__________(base16)?

1500(base10)+800(base16)+1111100(base2)+_________(base8)?=4,096(base16)

(2000/5(base10)+182(base16)+416(base10)+11100(base2)=_____________(base8)?

please..i will wait for your reply..thanks a lot

Thanks a lot…

thank you! I’m every difficult study this code but now is Ok when i have follow up this website…

sorry but i m not able 2 understand anything……..

THANK YOU SO MUCH………!!!!!!!!!!!!BUT STILL I NEED SOME PROBLEMS TO SOLVE……..!!!!!!!!!THATS OK…….!!!

Thanksssssss for the author. This was a very big help! More Power and God Bless you. =)

I’m really thankful to person who posted this and this was really helpful in my exam!!!!!!

simply you are awesome boss

wow sir,what a great steps to understand, truely respect you people!

very helpful information related to number system

making great future of mine awesome website

thank,s Fawad sir .you are great teacher……..

it’s realy very easy to under stand

How about converting decimal into hexadecimal?

@Batahi Mosha : It’s there, you missed it, almost mid post.

I realy learned the base of convesion process. thanks a lot for such a good teaching.

how about conveting binary to integral

its realy helping but i need to solve some questions given in home work .. :/ help me plz

really its easy to understand and easy to learn …

Even if it is good point

their is something that is needed in order to increase the knowledge for those student

i like the way that presented to us thank you

, Exactly as i needed , Thank You , may GOD bless you

good job man!!!!!!!!

very helpful for serlf studyyyyyyyyyyyyy…………

thnx alot …it really helped me

thank you very much.Now l can able to do any conversion.

Ιnformative article, totally what I needed.

WOW just what I was looking for. Came here by searching for learn the numeral systems