Python中的bytes,str,int等类型转换

在Python3.2中添加了int.from_bytes(bytes, byteorder, *, signed=False)

可实现不固定长度的bytes类型数据转int类型数据

1 >>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=True) ##signed标志是否为有符号数
2 -1024
3 >>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=False)
4 64512
5 >>> int.from_bytes(b'\x00\x00\x00\x14', byteorder='big', signed=True) ##byteorder标志小字节顺序还是大字节顺序
6 20
7 >>> int.from_bytes(b'\x00\x00\x00\x14', byteorder='little', signed=True)
8 335544320

 

 

posted on 2013-05-18 22:11  甘泉love若水  阅读(13638)  评论(0编辑  收藏  举报

导航