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

16,684

Solution 1

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.

Solution 2

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!!

Solution 3

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.

Share:
16,684
claws
Author by

claws

Updated on July 19, 2022

Comments

  • claws
    claws almost 2 years

    I've observed few reverse engineers, they convert decimal to hexadecimal so fast in mind. It's simply amazing. I never got chance to ask them. Personally, I really suck it this conversion and I always use a calculator for conversion.

    I was wondering if there is some kind of short cut for this conversion?

    I think especially for a reverse engineer & a low level (Assembly, Embedded) programmer. Its a BIG PLUS if he can count, add, subtract and think in terms of HEX instead of decimal. If you have any tips for this, kindly share.

  • claws
    claws over 13 years
    What is it? You just registered and answered my question?
  • caveman
    caveman over 13 years
    100 decimal is 0x64, while 0x100 is 256 also useful if looking at bytes. And you should know what the single bits are: 0x80, 0x40, 0x20, 0x10. Otherwise, practice makes you better.
  • caveman
    caveman over 13 years
    Also little error up there. 0x10000 is 64k, not 1Meg. That's 0x100000, ie. 5 zeros. Although I tend to think of it like 0x1_0000 as 64k and 0x10_0000 as a Meg.
  • nilsi
    nilsi almost 6 years
    Broken link. Paste the answer here instead