converting bytes to int in Java

前端 未结 5 1265
隐瞒了意图╮
隐瞒了意图╮ 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 06:04

    public int toInt(byte hb, byte lb)
    {
        return ((int)hb)<<8 + lb;
    }
    

提交回复
热议问题