Can we make unsigned byte in Java

前端 未结 16 1275
青春惊慌失措
青春惊慌失措 2020-11-22 08:02

I am trying to convert a signed byte in unsigned. The problem is the data I am receiving is unsigned and Java does not support unsigned byte, so when it reads the data it tr

16条回答
  •  故里飘歌
    2020-11-22 08:26

    If think you are looking for something like this.

    public static char toUnsigned(byte b) {
        return (char) (b >= 0 ? b : 256 + b);
    }
    

提交回复
热议问题