Short.reverseBytes() in Java

Short.reverseBytes(): This method is available in java.lang.Short class of Java.

Syntax:

short java.lang.Short.reverseBytes(short i)

This method takes one argument of type short as its parameter. This method returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified short value.

Parameters: One parameter is required for this method.

i: the value whose bytes are to be reversed.

Returns: the value obtained by reversing (or, equivalently, swapping)the bytes in the specified short value.

Exceptions: NA

Approach

Java

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

        short i = 5;
        System.out.println(Short.reverseBytes(i));
    }
}

Output:

1280


No comments:

Post a Comment