Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn hexadecimal into decimal using brain?

Tags:

hex

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?

like image 682
Ivan Prodanov Avatar asked May 26 '09 11:05

Ivan Prodanov


People also ask

How do you convert hex to decimal mentally?

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. NOTE: This is good only if you need to convert 2 digit hexadecimals.

Is hexadecimal human readable?

Hexadecimal allows humans to interact with binary in a human readable form. Hexadecimal is compact and easy for humans to read. Large numbers can be represented in a smaller number of digits, making them easier and more accurately read by humans. Hexadecimal can be easily converted to binary and vice verse.


4 Answers

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:

0x12 = 2 + (1 * 16) = 18

0x99 = 9 + (9 * 16) = 153

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

So,

0xFB = 11 + (15 * 16) = 251

like image 104
Andre Miller Avatar answered Oct 17 '22 20:10

Andre Miller


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 (from right to left).

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

like image 31
gbianchi Avatar answered Oct 17 '22 20:10

gbianchi


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.

also, 64=100, 32=50, B8=200

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

like image 29
John Saunders Avatar answered Oct 17 '22 21:10

John Saunders


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 hexadecimal number:

  1. Divide the hexadecimal 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.
like image 26
Chris Lutz Avatar answered Oct 17 '22 21:10

Chris Lutz