Integer and decimal conversion

Plastic -int

  • It used to calculate and compare

  • Py 3 only int

  • There Py2 int and long (eg: 3213123434534L, the suffix L indicates that it is a long type)

    Specific range:

    2**31~2**(31-1)       int
    2**63~2**(63-1)       long

Hexadecimal conversion

Decimal - 2 binary

  • Divisible by 2, to get the remainder, the output binary remainder, in turn, written from bottom to top, that is his binary.
Dividend remainder
15 1
7 1
3 1
1 1
0

​ 15 ---> 1111

  • bin (xxx): Decimal Binary transfer
  • eg: print (bin (15)) = 0b1111 0b binary flag

Binary --10 hex

  • eg: 1010 from right to left

    1010 = 0 * 2**0 + 1 * 2**1 + 0 * 2**2 + 1 * 2**3

    * 2 ** 0 0 0 The first digit is '1010' is, 2 is converted to binary, 0 is due to the second bit represents 0 power (power of ten represents 1, one hundred 2 represents the power of thousands of delegates to the third power)

  • int ( '' xxx '', several hex) to convert the radix "xxx" in decimal

  • eg: int ( "1010", 2) to convert the binary to decimal 1010

    print(int("1010",2)) = 10

to sum up:

  • Integer data type is immutable
  • Can be modified in situ called variable data type, it can not be modified in situ immutable data types, called
  • id () View the memory address space

Guess you like

Origin www.cnblogs.com/Guoxing-Z/p/11494971.html