Java.lang.Short.reverseBytes() Method
Advertisements
Description
The java.lang.Short.reverseBytes() method returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified short value.
Declaration
Following is the declaration for java.lang.Short.reverseBytes() method
public static short reverseBytes(short i)
Parameters
i -- This is the short value.
Return Value
This method returns the value obtained by reversing the bytes in the specified short value.
Exception
NA
Example
The following example shows the usage of java.lang.Short.reverseBytes() method.
package com.tutorialspoint;
import java.lang.*;
public class ShortDemo {
public static void main(String[] args) {
// assign value to short
short shortNum = 50;
/* returns the value after reversing the order of the bytes
in the binary representation of the specified short value. */
short shortValue = Short.reverseBytes(shortNum);
// displaying the reversed value
System.out.println("The reversed value is = " + shortValue);
}
}
Let us compile and run the above program, this will produce the following result:
The reversed value is = 12800