Byte.compareUnsigned() in Java

Byte.compareUnsigned(): This method is available in the java.lang.Byte class of Java.

Syntax:

int java.lang.Byte.compareUnsigned(byte x, byte y)

This method takes two arguments of type byte as its parameters. This method compares two-byte values numerically treating the values as unsigned.

Parameters: Two parameters are required for this method.

x: the first byte to compare.

y: the second byte to compare.

Returns:

1. The value 0 if x == y.

2. A value less than 0 if x < y is an unsigned value.

3 A value greater than 0 if x > y as unsigned values.

For Example:

Byte.compareUnsigned(2,1) = > It returns 1.

Approach

Java

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

        byte x = 2, y = 1;
        System.out.println(Byte.compareUnsigned(x, y));

    }
}

Output:

1

No comments:

Post a Comment