Python using the hexadecimal conversion function

Python using the hexadecimal conversion function

  About function uses several methods in Python binary conversion, do introduce a simple method of use, we used binary conversion function commonly used is int () (other binary conversion to decimal), bin () (decimal conversion binary), oct () (convert to decimal octal), hex () (convert decimal to hexadecimal).

  Let's say one by one under the usage of each function.

bin

  bin () function, is a decimal number into binary number. Wherein the bin () function is passed in decimal number, the type of digital data types.

v = 18
num = bin(v)
print(num)

'''
'0b10010'
'''

oct

  oct () function is the decimal numbers into octal numbers. Wherein OCT () function is passed in decimal number, the type of digital data types.

y = 30 
whether = Out (v)
 print (whether) 


'' ' 
' 0o36 ' 
' ''

int

  int () function, the other is the digital binary number is converted to decimal. Wherein the first parameter int () function is to be converted into other forms of digital binary string, the second parameter is the hexadecimal number of the first parameter, the first parameter that is passed is how many hexadecimal numbers in the second argument to pass a number of data type numeric type.

# 2 ---> 10 
y = ' 0b1111011 " whether = int (v 2 ) Print (whether) ' ' 123 ' '' # 8 ---> 10 V = " 011 " whether = int (v, 8 ) print (whether) '' ' 9 ' '' # 16 ---> 10 V = ' 0x12 ' whether = int (v, 16 ), print (whether) '' ' 18 ' ''

hex

  hex () function is to decimal numbers into hexadecimal numbers. Wherein hex () needs to be passed decimal number, the type of digital data types.

V = 87 
whether = hex (v)
 print (whether) 

'' ' 
' 0x57 ' 
' ''

  In addition to that sum up int () function outside, several other functions (bin (), oct (), hex ()) only need to pass a data and their data types are numeric types. int () function requires two incoming data, and the data type of the first data type are a string, the second parameter data corresponding to a first binary number.

 

Guess you like

Origin www.cnblogs.com/ZN-225/p/11291545.html