Hexadecimal Binary

ptrath12

Beta member
Messages
2
Location
Australia
I am trying to find an easier way of understanding hexadecimal binary. Can anyone help or send a useful link for this?

Thanks,
Pat
 
you want an easier way,

what do you currently not understand about it?
 
To understand numeric bases (which is what you are asking - in this case base 16 and base 2) you need to go back to first principles with decimal. The following example should start you off with an idea, but is by no means comprehensive. I'm sure there are plenty of good websites out there (like this: HowStuffWorks "Understanding Binary and Hexadecimal Number Systems")

First you need to divide you number into columns, where each column (starting from the right) is an order of magnitude larger than the previous:

123 -> 3*1's + 2*10's + 1*100's

For the sake of being pedantic, the above should be written more precisely as:

123 -> 3*(10^0) + 2*(10^1) + 1*(10^2)

Here you can clearly see we're talking about a decimal (base-10) number.

123 in binary is computed exactly the same (just lots more steps as each step accounts for fewer possible values, 2 states per column rather than 10):
*Note: remember that you can only have 1* or 0* in front of each block because binary only has 2 states

123 -> 1*(2^0) + 1*(2^1) + 0*(2^2) + 1*(2^3) + 1*(2^4) + 1*(2^5) + 1*(2^6)

which is more clearly verified by (remember that n^0 is always 1 for any value of n):

123 -> 1*(1) + 1*(2) + 0*(4) + 1*(8) + 1*(16) + 1*(32) + 1*(64)

123 -> 1 + 2 + 0 + 8 + 16 + 32 + 64

reading the numbers outside the brackets from right to left gives:

123 -> 1 1 1 1 0 1 1 (which calculator should verify is 123 in binary)

------------------------------------

Now for hexadecimal:

There are now 16 states for each column, 0-9 and A-F, therefore the number will most likely be fewer columns as each column can represent 6 more states

123 -> B*(16^0) + 7*(16^1)

Remeber that B is equivalent to 11 in decimal:

123 -> 11*(1) + 7*(16)

123 -> 11 + 112

Taking the values outside the brackets (from right to left) gives 7B as the hexadecimal value for 123.

-------

Obviously the above examples simply show why the result is the way it is, they don't let you work it out from a decimal starting point. For this you can think in blocks:

e.g.

123 < 160

160 would be 16*10 and therefore be A0 in hexadecimal (because A is 10 and it's in the second column from the right - the 16^1 column)

You now know the answer is less than A0

7*16 is 112, (which is 70 in hex) so you know the answer is larger than that, but we're close now - the core idea is find the multiple of your base (16) which is less than you desired number (123), but such that an increase of 1 would go beyond it (8*16 = 128, 128 > 123)

Having got to 112 with 0x70 (0x is the prefix for hex numbers), you know you need to add 11, the value for 11 in hex is B so the result becomes 0x7B.

I hope that helps explain these concepts a little, I think everyone has issues with this initially - once you've done any network programming you learn to read hex like it was english!
 
Back
Top Bottom