The digital data type (II)

  Ary

  1,10 hex

  2. Binary: 0b or 0B

  3, octal: 0o or 0O

  4, Hex: 0x or 0X

0b101     # Binary 
0o10      # octal 
0xF       # hexadecimal 
0xff      # hex

  Decimal to hexadecimal other

= 100 the n-         # default decimal 
Print (bin (the n-))   # is converted to binary 
Print (the OCT (the n-))   # octal 
Print (hex (the n-))   # is converted to hexadecimal

  NOTE: After conversion to a string  

  Other binary to decimal int ()

= I ' 110 ' 
Print (int (I, Base = 10))      # of raw data must be a string type to decimal 
Print (int (I))               # to decimal, the raw data may be a digital, fractional part is rounded , ignoring rounding 
Print (int (i, Base = 2))       # binary to decimal 
Print (int (i, Base = 8))       # octal to decimal 
Print (int (i, Base = 16))      # hex system to decimal

 NOTE: Use int () type conversion achieved:
  1. Float directly removing the decimal portion. Such as: int (9.9) the result is: 9
  2. Boolean True Switch 1, False goes to 0. Such as: int (True) Results 1
  3. conform integer format string (not floating-point format) is transferred directly to the corresponding integer, otherwise an error

  

Guess you like

Origin www.cnblogs.com/doc-wang/p/11839408.html