How do they convert Decimal to Hexadecimal so fast (in mind)?

http://quashnick.net/geek_stuff/HEX2DEC.html

Here is the procedure. Rest is math. if u can do multiplications and divisions on the fly you should not have problems in converting either decimal to hex or vise versa.


It is quite simple once you understand the base of the numbering systems involved. Hexadecimal is base 16 - so, 1(dec) = 0x01; but 16(dec) = 0x10.

whenever you see a decimal number, say, 39:

divide it by 16 and just take the quotient - this is 2 (2*16 = 32) remainder is 7 ( 39 - 32 )

The HEX value of decimal 39, is therefore: 0x27.

Now, convert it back to decimal: 0x27 = 2*16 + 7 = 39 decimal :)

Hope you got the idea!!


You need to know the basic conversions 0-16, 0x0-0xF and 0b0-0b1111 conversions by hart.

The rest you learn with repetition. The are some often repeated patterns to watch for.

Multiples:

  • 1024(1K) is 0x400
  • (1024*1024)1048567(1M) is 0x100000
  • just multiply with 4 to get the size of 4M as 0x400000.

Similar for bit positions you can learn the decimal values

  • The MSB of a 16 bit word is 0x8000 or 32768 or 32K
  • Thus next bit has a value is 0x4000 or 16384 or 16K

These patterns repeat everywhere and with time you will start to learn them.

If you have a binary representation it is easy to group the bits in groups of four and quickly convert to a binary representation.

The only realistic way to find the decimal value 0xA1B587DE is to use a calculator(or be unbelievably good at maths). But the nearest 1k boundary down from 0xA1B587DE is 0xA1B58400 which is easy if you know the patterns.

From your comments on opcode:
For RISC processors most instructions just the first few bits in an instruction word defines the family of instruction (mov, jump, and, or, ...) and the rest is just parameters. If you work with a processor enough you will start to learn them.