python Long to Byte Array of 2 byte using struct -


i converting long or int bytearray in python using struct

ba = struct.pack('h',12)

output : '\x0c\x00' length 2 bytes

but if convert ba = struct.pack('h',12345)

output : '90' need encode hex desired out put ba.encode('hex') in case output output : 3930 , length 4

why happening, should give 2 byte result without encoding ?

my usecase need convert long bytearray of desired bytearray size.

'90' 2 bytes. first byte 0x39 , second 0x30.

>>> hex(12345) '0x3039' 

tl;dr: getting correct result.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -