Convert unsigned byte to signed byte

前端 未结 5 1883
抹茶落季
抹茶落季 2020-12-17 21:37

Is there an easy and elegant way to convert an unsigned byte value to a signed byte value in java? For example, if all I have is the int value 240 (in binary (24 bits + 1111

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 21:46

    public int getUnsignedByte(byte[] bytes, int offset) {
        return (bytes[offset] & 0xFF);
    }
    

    should do the work.

提交回复
热议问题