java.lang.Byte toUnsignedInt(byte x)

Description

The toUnsignedInt(byte x) method of Byte class Converts 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.

Method Syntax

public static int toUnsignedInt(byte x)

Method Argument

Data Type Parameter Description
byte x the value to convert to an unsigned int

Method Returns

The toUnsignedInt(byte x) method of Byte class returns the argument converted to int by an unsigned conversion.

Compatibility

Requires Java 1.8 and up

Java Byte toUnsignedInt(byte x) Example

Below is a simple java example on the usage of toUnsignedInt(byte x) method of Byte class.

Basically on the above example, we have asked the user to enter a number on the console. Then we printed the result of the toUnsignedInt method. As you would have noticed positive numbers would result to the same number but for negative numbers that’s where we would see the difference in result.

Sample Output

Below is the sample output when you run the above example.

java Byte toUnsignedInt() example output