Conversion between decimal and hexadecimal

Decimal numbers into hexadecimal notation x

The decimal number x divided by 16, that is, x = q * 16 + r, r and obtain the remainder quotient q, r at this time is the remainder x hexadecimal value at the lowest level; after quotient q proceed more division operation, are obtained for each of the remainder r as the lower value of hexadecimal representation, until the value of q to a value less than 16, then the q-value is the highest value of the hexadecimal representation.
E.g:

        314156 = 19634*16 + 12  ( C )
         19634 = 1227*16 + 2    ( 2 )
          1227 = 76*16 + 11     ( B )
            76 = 4*16 + 12      ( C )
             4 = 0.16 + 4       ( 4 )

So 314156 = 0x4CB2C

Hexadecimal to decimal conversion

Digit hexadecimal number of weights 16, the hexadecimal number is multiplied by each corresponding bit weight, the sum of the sum to a decimal value.

Example:

0x7C0 =
7*162 + 13*161 + 0*160 =
1792 + 193 + 0 =
1984
G

Guess you like

Origin www.cnblogs.com/haiiiiiyun/p/12525309.html