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








Byte toUnsignedLong(byte x) converts the byte to a long by an unsigned conversion.

Zero and positive byte values converts to an equal long value.

Negative byte values converts to a long value equal to the input + 256.

Syntax

toUnsignedLong has the following syntax.

public static long toUnsignedLong(byte x)

Parameters

toUnsignedLong has the following parameters.

x
the value to convert to an unsigned long

Return

toUnsignedLong returns the byte converted to long by an unsigned conversion





Example

The following example shows how to use toUnsignedLong.

/*from  w ww  .ja  v a 2 s  .  c om*/
public class Main {
  public static void main(String...args){
    byte b = 2;
    System.out.println(Byte.toUnsignedLong(b));
    
    b = -2;
    System.out.println(Byte.toUnsignedLong(b));
  }
}

The code above generates the following result.