首页 > 编程知识 正文

python二进制转八进制,python将整数转化为十六进制

时间:2023-05-05 16:54:43 阅读:59343 作者:1053

Im building a server in python,ineedtoconvertadecimalvaluetohexlikethis :

let ' ssaythepacketstartby4byteswhichdefinethepacketlenght 3360

00 00 00 00

ifthe len (包)=255 we would send :

00 00 00 ff

nowmyproblemisthatsometimesthepacketisbiggerthan 256 as for example 336,then it would be :

00 00 01 50

i dont know how to do that in python,andiwillreallyappreciateanyhelp。

解决方案导入结构

struct.pack(I ),336 ) )。

'x00x00x01P '

thestructmodulepacksandunpackspythonvaluesintobytes.the ' I ' formatmeansbig-endian4- byte integer。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。