您的位置:首页 > 其它

Convert int to byte array

2015-03-25 20:48 387 查看
iLength # 32 bit integer

data = array.array('B')
data.append( ((iLength>>24)&0xFF) )
data.append( ((iLength>>16)&0xFF) )
data.append( ((iLength>>8)&0xFF) )
data.append( ((iLength)&0xFF) )
file_out.write( data )


-------------

Ref:http://stackoverflow.com/questions/16887493/write-a-binary-integer-or-string-to-a-file-in-python
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: