IPB

ISO Image Creator

Welcome Guest ( Log In | Register )

> Hex to Binary Conversions, for "do-it-yourself" people
bfarber
post Nov 30 2004, 12:36 PM
Post #1


Administrator
Group Icon

Group: Admin
Posts: 10,302
Joined: 9-February 03
From: Jacksonville, FL
Member No.: 1
 United States


This is not a fancy page. No nice graphics or animations and no music to listen to. I created this page so that anyone that needed to learn hex to binary to decimal conversions could do so easily (well, as easily as I can explain it).


The Binary Conversions



First of all, let's take a look at decimal numbers. We have 10 digits in our standard number system. They are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. I'm sure just about anyone reading this is familiar with the decimal number system.


Well...you can also count in one of many other number systems. Binary utilizes only two digits, 0 and 1, but can count just as high as decimal. You'll just have a longer number.


Because you need to know how to convert to the binary number system in order to convert from hex to decimal and vice versa, first I will show you how to convert your decimal number to binary and back again.


Let's pick a test number. I choose 467 (at random). Now we will convert 467 to a bunch of 1's and 0's that have the same meaning.


The way that I do this is to create a guide. This guide will look just like this:


2048 1024 512 256 128 64 32 16 8 4 2 1
211 210 29 28 27 26 25 24 23 22 21 20



You will notice that each place in binary doubles. This is because you are just adding 1 to the exponent each time, in effect multiplying the number by two. If you have 24 this equals 16. If you go to the next place in binary, you are moving to 25 which equals 32. Get it? Oh yeah, any number to the 0 power equals 1. This is any number system. Start from the right and work your way left (until you get good at this). Do 20 and write a 1 above it. Then move to the next place. For most practical applications that you will do the conversions manually (i.e. without a calculator), then writing your chart up to 2048 should be plenty (although it can go higher and sometimes must as I will show later).


So now we have the chart. You might ask "What good is that if I don't understand it?" or "So what do you do with it?". It's simple. If you study it long enough, you'll see just how it all works together, but it's not important for our uses. We are just concerned with the actual conversion.


Start all the way at the highest number and say to yourself "Is this higher than the number I want to convert?" If it is, then move to the next place and do the same thing. Since we are converting 467, you'll notice that we have to go all the way down to 256 before we get to a number that is not higher than the number we are working with. When you get to the first number that is not higher than the one you want to convert, put a "1" under that number.


In our scenario here, we currently have this...


2048 1024 512 256 128 64 32 16 8 4 2 1
211 210 29 28 27 26 25 24 23 22 21 20
   1        



You can also fill in zeros in any of the places that you skip, like those first three spaces. You do not have to though. If you do, it is more for your visual benefit so you can see where you are at.


Ok. Now we have 256. Well, that isn't 467, which is what we need. So now, we go to the next spot. 256 + 128 = 384. In our case, this still isn't higher than the number we want (467). So now we put a "1" under 128.


Ok. Next place. We have 384 so far. 384 + 64 = 448. Wow, we still haven't gone over our limit. Guess what? That means you put a "1" under 64 as well.

To recap, we have this so far:


2048 1024 512 256 128 64 32 16 8 4 2 1
211 210 29 28 27 26 25 24 23 22 21 20
   111      



Now we are at 448. 448 + 32 = 480. Uh oh. This is too high. We only need 467. As soon as this happens, you must put a "0" under that place and skip it in the additions. This means we are still at 448. 448 + 16= 464. Cool. This isn't higher than 467 so we put a "1" under 16. Continuing down, we put a "0" under the 8, a "0" under the 4, and then a "1" under the 2 and 1 (because 2 + 1 = 3 and we still need 3 to equal 467).


Now we have our converted binary number.


2048 1024 512 256 128 64 32 16 8 4 2 1
211 210 29 28 27 26 25 24 23 22 21 20
   111010011



As you can see from our chart now, the binary number that equals 467 is 111010011.


That wasn't too bad, was it? Well, guess what? To convert from binary to decimal you do that exact same thing, only backwards. If you wanted to check this number for accuracy, you would make the chart, then put the number underneath it (making sure to line up the positions correctly) and add every spot that has a 1. In our case we have 256 + 128 + 64 + 16 + 2 + 1 = 467! Great, we did it.


The Hexadecimal Conversions



Well, class we've come a long way in the past hour. Now we can convert decimal numbers to binary numbers. But a lot of computer applications need and use hex numbers. So we want to know how to get those too, right? Well, it's not too difficult. Let's take a look.


First of all, let's look at the similarities between hex and decimal number systems. Hex is base 16 and decimal is base 10. This means that there are 6 more digits in hex than in decimal. I usually draw the following chart to show this:


DecimalHex
00
11
22
33
44
55
66
77
88
99
10A
11B
12C
13D
14E
15F



Now you may say "I thought this was base 16? That only goes up to 15." You have to remember that in math, 0 is considered a number. So 0-15 is actually 16 different numbers.


You can see the relationship between hex and decimal easily. If only it was just as easy to convert between the two. Unfortunately, as I stated in the beginning, it isn't. You must first convert to binary to convert to the other number system (and this is true for most number systems besides just hex and decimal such as octal (base 8)).


What we will do now, is create our cheat guide for these conversions, just as we did earlier. It looks like the guide I just drew plus the binary equivalants:


DecimalHexBinary
000000
110001
220010
330011
440100
550101
660110
770111
881000
991001
10A1010
11B1011
12C1100
13D1101
14E1110
15F1111



Unless you intend to work with these numbers daily, I wouldn't worry about the conversions I did for you above. That is the cheat guide I always use and I have gotten pretty quick at it. However, if you feel that you really want to know how I came about the above binary numbers, look at the binary cheat guide above. It's the same concept. 10, for example, is 1010 because 8 + 2 = 10.


Now, let's do a decimal to hex conversion first. Let's convert our 467 to hex. You must first convert the decimal number to binary. Luckily, we already have the binary equivalent. It's 111010011.


The next step we take is to separate the binary number we come up with into chunks of four, starting on the right hand side. In our case we will get 1 1101 0011. If you have any chunks at the beginning that are not 4 digits long like we do here, just add 0's to the beginning. Doing this we come up with 0001 1101 0011.


Take the chunks of four, and starting on the left hand side, use the cheat guide to convert them to hex. It's that simple! What we come up with is this:

0001 = 1

1101 = D

0011 = 3

So our end result is 1D3. 1D3 in hex equals 467 in binary.


That was easy wasn't it? Now let's convert hex to decimal. To show you this, I'll pick a hex number at random. Let's use A59.


The first thing we'll do is separate the hex digits like so: A 5 9 and then we'll convert those digits to binary:

A = 1010

5 = 0101

9 = 1001

So now our binary equivalent of A59 is 1010 0101 1001. The only thing we need to do now is convert the binary number to decimal as I showed you above. In our case we get the following:


2048 1024 512 256 128 64 32 16 8 4 2 1
211 210 29 28 27 26 25 24 23 22 21 20
101001011001



The only thing left to do is add. We have 2048 + 512 + 64 + 16 + 8 + 1 = 2649. So A59 in hex equals 2649 in decimal. That wasn't bad at all.


Now as you can probably see from this, if we only have 3 hex digits then our binary chart only needs to go up to 2048. If we have 4, then we will need to add up to four more binary positions (4096, 8192, 16384, and 32768). As you can see, the higher the hex number goes, the higher the other number systems must climb to meet the hex number. For most purposes, 2048 is high enough, but occasionally, you will have to keep climbing until you can meet your needs.


Closing



Well, I hope this helps someone out there. It's not a "teacher's edition" or anything, just something I threw together to show people who need to do hex-binary-decimal conversions how it is done, manually. Your other option is to get a scientific calculator, but why spend money you don't need to spend, right? wink.gif

Bfarber
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 22nd May 2012 - 10:26 AM

  Page top

Webber Enhanced skin created by Im4eversmart of RuneHQ.

  Privacy Policy 1 2 3 4 5

IPS Driver Error

IPS Driver Error

There appears to be an error with the database.
You can try to refresh the page by clicking here