Chinaunix首页 | 论坛 | 博客
  • 博客访问: 753520
  • 博文数量: 199
  • 博客积分: 3584
  • 博客等级: 中校
  • 技术积分: 2193
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-12 21:18
文章分类

全部博文(199)

文章存档

2018年(6)

2013年(14)

2012年(30)

2011年(28)

2010年(24)

2009年(86)

2008年(11)

分类: Python/Ruby

2018-01-09 00:11:46

import sys
import pdb


fileName = 'test.hex'


def hextobytesfromfile():
    with open(fileName, 'r') as fileIn:
        for lineHex in fileIn:
            print(lineHex)
            #print(len(lineHex))
            #pdb.set_trace()
            if lineHex[-1] is '\n':
                lineBytes = bytes.fromhex(lineHex[1:-1])  #bytearray
            else:
                lineBytes = bytes.fromhex(lineHex[1:])   #last line
            #print(lineBytes)
            print(list(lineBytes))
            print(lineBytes.hex())


if __name__ == '__main__':
    hextobytesfromfile()
阅读(501) | 评论(0) | 转发(0) |
0

上一篇:crc16

下一篇:python crc16

给主人留下些什么吧!~~