I'm required to send a 32bit integer over a serial connection like so: 0xc6bf6f34 should become: b'\xc6\xbf\x6f\x34'.
To that end, I created this, but, as always after such coding, I wondered if it's pythonicism could be improved with something in the standard libary:
def ltonlba(value):
''' ltonlba : Long to Network Long Byte Array '''
from socket import htonl
value = htonl(value)
ba = b''
for i in range(4):
ba += chr((value) & 0xff)
value >>= 8
return ba