How do I split an integer into 2 byte binary?

前端 未结 7 1247
再見小時候
再見小時候 2020-12-12 22:22

Given

private int width = 400;
private byte [] data = new byte [2];  

I want to split the integer \"width\" into two bytes and load data[0]

7条回答
  •  星月不相逢
    2020-12-12 22:30

    I suggest you have a look at the source for HeapByteBuffer. It has the conversion code for all primitive data types. (In fact you could just use a ByteBuffer ;)

提交回复
热议问题