18 May 2010

Convert from Hex to Binary by eye

Here's a simple way to convert from Hexdecimals to Binary just by eye.
suppose you have the following hex expression:

int x = 0xb123f;

and you need to know the binary (or even decimal) representation of this integer.

first, divide this integer into 2 characters (hence, 2 characters in Hex = 1 byte) from right:
so, it will be:
b 12 3f
then write the binary representation for each symbol:
b (11 in decimal) = 1011
1 = 0001
2 = 0010
3 = 0011
f = (15 in decimal) 1111
so, you have the following bit pattern:
0000 1011 0001 0010 0011 1111 (= 725567 in decimal)

note: hence we have 5 hex symbols, we added 0 to the left, and this explains why we add 0000 at the left.


thats all.

2 comments:

SalehRam said...

:D
That will help me much :D
Thanks dude :)

BTW, Can I post this into my blog, with the reference to this link?

mhewedy said...

Yes of course my brother.
ur welcome :)