python读取十六进制文件,如何用python读取十六进制数据?

本文介绍如何在Python中解析来自C#应用的十六进制数据,使用等价的枚举类来检查标志,并通过struct模块或ord()函数处理字节表示。
摘要由CSDN通过智能技术生成

I have this c# app that Im trying to cooperate with a app written in python. The c# app send simple commands to the python app, for instance my c# app is sending the following:

[Flags]

public enum GameRobotCommands

{

reset = 0x0,

turncenter = 0x1,

turnright = 0x2,

turnleft = 0x4,

standstill = 0x8,

moveforward = 0x10,

movebackward = 0x20,

utility1 = 0x40,

utility2 = 0x80

}

I'm doing this over TCP and got the TCP up and running, but can I plainly do this in Python to check flags:

if (self.data &= 0x2) == 0x2:

#make the robot turn right code

Is there a way in python I can define the same enums that I have in c# (for higher code readability)?

解决方案

Hexadecimal notation is just tha

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值