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