Integer reverse() Method In Java Last Updated : 07 Jul, 2018 Comments Improve Suggest changes Like Article Like Report The java.lang.Integer.reverse() is an inbuilt method in Java and is used to return the reverse order of the bits in the two's complement binary representation of the specified int value. Syntax: public static int reverse(int a) Parameters: The parameter a is an integer value whose bits are to be reversed. Return Value: The method returns the value which is obtained by reversing the order of the bits in the specified int value. Examples: Input: 86 Output: 1778384896 Explanation: Consider an integer a = 86 Binary Representation = 1010110 The number of one bit = 4 After reversing it is = 1778384896 Input: 168 Output: 352321536 Below programs illustrate the java.lang.Integer.reverse() method: Program 1: For a positive number. java // Java program to illustrate the // Java.lang.Integer.reverse() method import java.lang.*; public class geeks { public static void main(String[] args) { int a = 168; System.out.println("Number = " + a); // It returns the value obtained by reversing order of the bits System.out.println("By reversing we get = " + Integer.reverse(a)); } } Output: Number = 168 By reversing we get = 352321536 Program 2: For a Negative number. java // Java program to illustrate the // Java.lang.Integer.reverse() method import java.lang.*; public class geeks { public static void main(String[] args) { int a = -72; System.out.println("Number = " + a); // It returns the value obtained by reversing order of the bits System.out.println("By reversing we get = " + Integer.reverse(a)); } } Output: Number = -72 By reversing we get = 503316479 Program 3: For a decimal value and string. Note: It throws an error message when a decimal value or string is passed as an argument. java // Java program to illustrate the // Java.lang.Integer.reverse() method import java.lang.*; public class geeks { public static void main(String[] args) { int a = 37.9; System.out.println("Number = " + a); // It returns the value obtained by reversing order of the bits in // the specified int value System.out.println("By reversing we get = " + Integer.reverse(a)); a = "21"; System.out.println("Number = " + a); // It returns the value obtained by reversing order of the bits in // the specified int value System.out.println("By reversing we get = " + Integer.reverse(a)); } } Output: prog.java:9: error: incompatible types: possible lossy conversion from double to int int a = 37.9; ^ prog.java:17: error: incompatible types: String cannot be converted to int a = "21"; ^ 2 errors Comment More infoAdvertise with us Next Article Integer reverse() Method In Java ankita_chowrasia Follow Improve Article Tags : Java Java-lang package Java-Functions Java-Integer Practice Tags : Java Similar Reads Integer reverseBytes() Method in Java The java.lang.Integer.reverseBytes(int a) is a built-in method which returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified int value. Syntax : public static int reverseBytes(int a) Parameter: The method takes one parameter a of integer 3 min read Integer sum() Method in Java The java.lang.Integer.sum() is a built-in method in java that returns the sum of its arguments. The method adds two integers together as per the + operator. Syntax : public static int sum(int a, int b) Parameter: The method accepts two parameters that are to be added with each other: a : the first i 2 min read Integer shortValue() Method in Java The Integer.shortValue() is an inbuilt method of java.lang which returns the value of this Integer in the short type . Syntax: public short shortValue() Parameters: The method does not take any parameters. Return Value: The method returns the integer value represented by this object after converting 2 min read Integer signum() Method in Java The signum function is an odd mathematical function that extracts the sign of a real number. The signum function is also known as sign function. The Integer.signum() method of java.lang returns the signum function of the specified integer value. For a positive value, a negative value and zero the me 3 min read BigInteger remainder() Method in Java The java.math.BigInteger.remainder(BigInteger big) method returns a BigInteger whose value is equal to (this BigInteger % big(BigInteger passed as parameter)).The remainder operation finds the remainder after division of this BigInteger by another BigInteger passed as parameter. Syntax: public BigIn 3 min read Java Integer bitCount() Method The bitCount() method of Integer class of java.lang package returns the count of set bits in a positive number. For negative numbers, it returns the count of set bits in its 2s complement form. This function is sometimes referred to as the population count. Syntax:public static int bitCount(int n)Pa 2 min read Integer decode() Method in Java It is often seen that any integer within (" ") is also considered as string, then it is needed to decode that into the integer. The main function of java.lang.Integer.decode() method is to decode a String into an Integer. The method also accepts decimal, hexadecimal, and octal numbers. Syntax : publ 2 min read BigInteger setBit() Method in Java The java.math.BigInteger.setbit(index) method returns a Big-integer whose value is equivalent to this Big-integer with the designated bit set. The method computes (this | (1<<n)). The bit at index n of binary representation of Big-integer will be set means converted to 1. Syntax: public BigInt 2 min read Integer toOctalString() Method in Java Octal is the base-8 number system and uses the digits 0 to 7 in operation. Octal is widely used in computing on systems like the PDP-8, and IBM mainframes employed 12-bit, 24-bit or 36-bit words. The Java.lang.Integer.toOctalString() method is a built-in function in Java that is used to return a str 3 min read Integer intValue() Method in Java intValue() of Integer class that is present inside java.lang package is an inbuilt method in java that returns the value of this integer as an int which is inherited from Number Class. The package view is as follows: --> java.lang Package --> Integer Class --> intValue() Method Syntax: publ 3 min read Like