Convert int to byte array

833 단어 convert
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

좋은 웹페이지 즐겨찾기