converting bytes to int in Java

前端 未结 5 1224
隐瞒了意图╮
隐瞒了意图╮ 2021-01-05 05:24

I need to convert 2 bytes (2\'s complement) into an int in Java code. how do I do it?

toInt(byte hb, byte lb)
{

}
5条回答
  •  独厮守ぢ
    2021-01-05 05:51

    For those of you who are looking for the Little Endian value:

    int num = ByteBuffer.wrap(b, 0, 2).order(LITTLE_ENDIAN).char.toInt()
    

提交回复
热议问题