Search code examples
javaintunsigned-integer

How to print byte in unsign format in Java


I need to print a variable of type byte in an unsigned format. How do I do that?


Solution

  • Are you saying you are starting with a signed int and want the absolute value? You could do something like this:

        byte b = Byte.parseByte("-9");
        int i = (int) b;
    
        System.out.println(Math.abs(i));