Convert HEX to DEC in your head

 

Just a reminder for myself how to convert HEX to DEC and maybe backwards in my head.


The original article is from stackoverflow, you can find it here though: http://stackoverflow.com/questions/910309/how-to-turn-hexadecimal-into-decimal-using-brain

 

So here it goes:

 

this is the equation I'm using in my head 

0x15 = 5+(1*16) = 21

For the oposite I just do educated guess in my head

21, that means 16 goes in once so 0x1_

21-16 = 5 so 0x15

 

How about 4 byte HEX number?

Like this:

0xAB89

0xAB = 11+(10*16) = 171

171*256 = 43776

0x89 = 9+(8*16) = 137

43776+137 = 43913

 

How about 4 byte DEC to HEX?


38908

 

38908/256 = 151

151/16 = 9 = 0x9_

151%16 = 7 so upper bytes = 0x97

 

38908%256 = 252

252/16 = 15  = 0xF_

252%16 = 12 = 0xFC
 

 

So 38908 = 0x97FC




ADVERTISEMENT