Short reverseBytes() in Java with Examples Last Updated : 05 Dec, 2018 Comments Improve Suggest changes Like Article Like Report 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. Syntax : 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. Examples: 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. java // Java program to illustrate the // Short.reverseBytes() method import java.lang.*; public class Geeks { public static void main(String[] args) { // Create a Short instance short a = 61; // Print the value before reversal of Bytes System.out.println("Original value = " + a); // Reverse the bytes in the specified short value // Using reverseBytes() method System.out.println("After reversing the bytes : \n" + "New value : " + Short.reverseBytes(a)); } } Output: Original value = 61 After reversing the bytes : New value : 15616 Program 2: For a negative number. java // Java program to illustrate the // Short.reverseBytes() method import java.lang.*; public class Geeks { public static void main(String[] args) { // Create a Short instance short a = -45; // Print the value before reversal of Bytes System.out.println("Original value = " + a); // Reverse the bytes in the specified short value // Using reverseBytes() method System.out.println("After reversing the bytes : \n" + "New value : " + Short.reverseBytes(a)); } } Output: Original value = -45 After reversing the bytes : New value : -11265 Comment More infoAdvertise with us S Sruti Rai Follow Improve Article Tags : Misc Java java-basics Java-lang package Java-Functions Java-Short +2 More Practice Tags : JavaMisc Similar Reads Character.reverseBytes() in Java with examples The Character.reverseBytes() method in Java is a utility function from the java.lang.Character class. This method is used to reverse the order of the two bytes in a given 16-bit Unicode character (char). All Java characters are two bytes. It is useful when we work with systems or protocols that use 2 min read Random nextBytes() method in Java with Examples The nextBytes() method of Random class places the generated random bytes into an user-supplied byte array. Syntax: public void nextBytes(byte[] bytes) Parameters: The function accepts a single parameter bytes which is the non-null byte array in which to put the random bytes. Return Value: This metho 2 min read Scanner nextByte() method in Java with Examples The nextByte(radix) method of java.util.Scanner class scans the next token of the input as a Byte. If the translation is successful, the scanner advances past the input that matched. If the parameter radix is not passed, then it behaves similarly as nextByte(radix) where the radix is assumed to be t 5 min read Byte shortValue() method in Java with examples The shortValue() method of Byte class is a built in method in Java which is used to return the value of this Byte object as short. Syntax ByteObject.shortValue() Return Value: It returns the value of ByteObject as short. Below is the implementation of shortValue() method in Java: Example 1: Java // 2 min read Field setByte() method in Java with Examples setByte() method of java.lang.reflect.Field used to set the value of a field as a byte on the specified object. When you need to set the value of a field of an object as byte then you can use this method to set value over an Object. Syntax: public void setByte(Object obj, byte b) throws IllegalArgum 3 min read Like