Convert int to byte array

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

posted on 2015-03-25 20:48  奋进的苦瓜  阅读(339)  评论(0编辑  收藏  举报