tags:

views:

1756

answers:

5

Hello,

Opening the calculator to do such tiny stuff appears annoying to me ,and I strongly believe in ths saying "the more you know,the better!" so here I am asking you how to convert hexadecimal to decimal.

Till that moment I use the following formula:

Hex:        Decimal:
12          12+6
22          22+2*6
34          34+3*6
49          49+4*6
99          99+9*6

I get confused when I move on at higher numbers like C0 or FB

What is the formula(brain,not functional) that you're using?

+6  A: 

I pretty much stopped doing this when I found the hex numbers I was working with were 32 bits. Not much fun there.

For smaller numbers, I (eventually) memorized some patterns: 10 = 16, 20 = 32, 40 = 64, 80 = 128 (because 100 = 256, and 80 is one bit less). 200 = 512 I remember because of some machine I used to use whose page size was 512 (no longer remember what machine!). 1000 = 4096 because that's another machine's page size.

That's about all. Beyond that, I add.

John Saunders
+2  A: 

Mmm.. that's not the formula.. that's not even somewhat like the formula...

The formula is:

X*16^y where X is the number you want to convert and y is the position for the number (begging from the end to the start)

so.. if you want to convert DA145 to decimal would be..

5 * 16^0 + 4 * 16^1 + 1 * 16^2 + 10 * 16^3 + 13 * 16^4

And you have to remember that the letter are:
A - 10
B - 11
C - 12
D - 13
E - 14
F - 15

gbianchi
His formula is completely correct (and not merely coincidentally) for the class of numbers on which it operates. It just can't handle more than 2 digits or any of the alpha-digits.
sblom
+5  A: 

If you consider that hexadecimal is base 16, its actually quite easy:

Start from the least significant digit and work towards the most significant (right to left) and multiply the digit with increasing powers of 16, then sum the result.

For example:

12h = 2 + (1 * 16) = 18

99h = 9 + (9 * 16) = 153

Then, remember that A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15

So,

FBh = 11 + (15 * 16) = 251

Andre Miller
+4  A: 

For the record, your brain does use a functional method of finding the answer. Here's the function my brain uses to find the value of a hexidecimal number:

  1. Divide the decimal number into individual digits.
  2. Convert each digit to it's decimal value (so 0-9 stay the same, A is 10, B is 11, etc.)
  3. Starting at the rightmost digit, multiply each value by 16^X power, where X is the distance from the rightmost digit (so the rightmost digit is 16^0, or 1, next is 16^1, or 16, next is 16^2, or 256, etc.)
  4. Add all the values together.
Chris Lutz
+2  A: 

Memorize the decimal values of 20h, 40h, and so on, up to E0h. (I suppose you already know 100h.) Then get the decimal values if other numbers by adding or subtracting a number from 1 to 16.

Robert L