python3ならintとbytesの変換が楽勝になる - BlankTar
>>> a = 128
>>> a.to_bytes(2, 'big') # 2バイトでビッグエンディアン
b'\x00\x80'
>>> a.to_bytes(4, 'little') # 4バイトでリトルエンディアン
b'\x80\x00\x00\x00'
python3のbytes型とstr型の比較と変換方法 | Python Snippets
python3ならintとbytesの変換が楽勝になる - BlankTar
>>> a = 128
>>> a.to_bytes(2, 'big') # 2バイトでビッグエンディアン
b'\x00\x80'
>>> a.to_bytes(4, 'little') # 4バイトでリトルエンディアン
b'\x80\x00\x00\x00'
python3のbytes型とstr型の比較と変換方法 | Python Snippets