Can we make unsigned byte in Java

前端 未结 16 1049
青春惊慌失措
青春惊慌失措 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 08:48

    There is no unsigned byte in Java, but if you want to display a byte, you can do,

    int myInt = 144;
    
    byte myByte = (byte) myInt;
    
    char myChar = (char) (myByte & 0xFF);
    
    System.out.println("myChar :" + Integer.toHexString(myChar));
    

    Output:

    myChar : 90
    

    For more information, please check, How to display a hex/byte value in Java.

提交回复
热议问题