Short reverseBytes() in Java with Examples
The reverseBytes() method of Short class is a built in method in Java which is used to return the value obtained by reversing the order of the bytes in the two’s complement representation of the specified short value.
public static short reverseBytes(short a)
Parameter: The method takes one parameter a of short type whose bytes are to be reversed.
Return Value: The method will return the value obtained by reversing the bytes in the specified short value.
Input: 75 Output: 1258291200 Explanation: Consider an short a = 75 Binary Representation = 1001011 Number of one bit = 4 After reversing the bytes = 1258291200 Input: -43 Output: -704643073
Below programs illustrate the Short.reverseBytes() method:
Program 1: For a positive number.
Original value = 61 After reversing the bytes : New value : 15616
Program 2: For a negative number.
Original value = -45 After reversing the bytes : New value : -11265