python3 string, integer conversion between binary and forwarding (MAC address \ binary address forwarding the IP method)

 

   
1, decimal string to Integer
int('12') ==12
2, character to Integer
ord('a')==97
3, hexadecimal characters to Integer
int('a',16) == 10
MAC Address integer
例: a = FF: FF: FF: FF: FF: FF'.split (:)
int(a[0],16) = 255
int(a[1],16) = 255
int(a[2],16) = 255
int(a[3],16) = 255
int(a[4],16) = 255
int(a[5],16) = 255
4, Integer to character
chr(65) == 'A'
5, the data production section packets can be directly pressed into the binary approach employed
Pressed into the binary method
String directly into the For example: b'welcome to china '
The method of press-fitting integer
struct.pack('>B',255)
 
Reprinted from: http: //blog.sina.com.cn/s/blog_4c86552f0102x9fp.html
 

Guess you like

Origin www.cnblogs.com/xibuhaohao/p/12627409.html