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