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

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM