Java Integer reverse() Method

The reverse() method of Java Integer class numerically returns the value obtained by reversing the order of the bits in the 2's complement binary representation of the specified integer value.

Syntax:

Following is the declaration of reverse() method:

Parameter:

DataTypeParameterDescriptionRequired/Optional
intiInteger value whose bits are to be reversed.Required

Returns:

The reverse() method returns the numeric value obtained by reversing order of the bits in the specified int value.

Exceptions:

NA

Compatibility Version:

Java 1.5 and above

Example 1

Output:

Number = 202
After reversing = 1392508928

Example 2

Output:

Enter Integer Value: 140
Number = 140
Binary Representation = 10001100
After reversing = 822083584

Example 3

Output:

Number = 202
Binary Representation = 11001010
After reversing = 1392508928

Number = -50
Binary Representation = 11111111111111111111111111001110
After reversing = 1946157055

Example 4

Output:

Enter Number from console: 3456546
Result: 4935149145179553792