Java Data Type Tutorial - Byte toUnsignedInt(byte x) example








Byte toUnsignedInt(byte x) converts a byte to unsigned int.

Zero and positive byte values converts to a numerically equal int value.

Negative byte values converts an int equal to the input + 256.

Syntax

toUnsignedInt has the following syntax.

public static int toUnsignedInt(byte x)

Parameters

toUnsignedInt has the following parameters.

x
the value to convert to an unsigned int

Return

toUnsignedInt returns the byte converted to int by an unsigned conversion

Example

The following example shows how to use toUnsignedInt.

/*w w w.  j  a va2s . c o  m*/
public class Main {
  public static void main(String...args){
    byte b = 2;
    System.out.println(Byte.toUnsignedInt(b));
    
    b = -2;
    System.out.println(Byte.toUnsignedInt(b));
  }
}

The code above generates the following result.