Java.lang Package Classes

Java Byte - toUnsignedInt() Method



The java.lang.Byte.toUnsignedInt() method is used to convert the argument to an int by an unsigned conversion. In an unsigned conversion to an int, the high-order 24 bits of the int are zero and the low-order 8 bits are equal to the bits of the byte argument. Consequently, zero and positive byte values are mapped to a numerically equal int value and negative byte values are mapped to an int value equal to the input plus 28.

Syntax

public static int toUnsignedInt(byte x)

Parameters

x Specify the value to convert to an unsigned int.

Return Value

Returns the argument converted to int by an unsigned conversion.

Exception

NA.

Example:

In the example below, the java.lang.Byte.toUnsignedInt() method is used to convert the given byte value to an int by an unsigned conversion.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {

    //creating byte values
    byte x = 25;
    byte y = -25;

    //printing UnsignedInt value of byte values
    System.out.println("UnsignedInt value of x is: " + Byte.toUnsignedInt(x)); 
    System.out.println("UnsignedInt value of y is: " + Byte.toUnsignedInt(y));  
  }
}

The output of the above code will be:

UnsignedInt value of x is: 25
UnsignedInt value of y is: 231

❮ Java.lang - Byte