-2

I have some python code need to phase to java,
python code :

>>> struct.pack('h', 19)
b'\x13\x00'

I want to know how it phase to java, thanks~

HenryChuang
  • 1,449
  • 17
  • 28

1 Answers1

0

Use a DataOutputStream with a ByteArrayOutputStram

For example:

ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream d = new DataOutputStream(b);
d.writeShort(19);
byte[] result = b.toByteArray();
PureGero
  • 937
  • 2
  • 8
  • 16