Python3 显示bytes中的值
2015-07-31 19:00
489 查看
根据这个图,结合struct
def DispBytes(b):
'''把 bytes 中相应的值转成字串后输出
t = b'\x023\x02' --> DispBytes(t) '02 33 02'
'''
import struct
disp = ''
if type(b) == bytearray:
b = bytes(b)
if type(b) == bytes:
tup = struct.unpack('B'*len(b),b)# 转换成元组
ls = list(tup)
for i in range(len(ls)):
if(i == 0):
disp += '{0:02X}'.format(ls[i])
else:
disp += ' {0:02X}'.format(ls[i])
return disp
相关文章推荐
- python中的getopt模块
- python 的使用:getattr,hasattr
- python_getopt解析命令行输入参数的使用
- Python实现Table To Point代码
- Python实现Table To Point代码 分类: Python 2015-07-31 18:45 3人阅读 评论(0) 收藏
- python 之 分割参数getopt
- python2在pycharm中的中文乱码问题处理方式
- python3.x中的urllib模块
- Python实现fibnacci
- Python初步
- Python调用windows下DLL详解 - ctypes库的使用
- python 函数式编程
- Python GUI编程各种实现的对比
- python Iterable和Iterator
- Python中的局部变量和全局变量
- python range()函数
- python实现爬图,不要再爬妹子图了,太没品
- python的range()函数用法
- spark 集群运行python作业
- python 生成器