Java Long - reverse() Method
The java.lang.Long.reverse() method returns the value obtained by reversing the order of the bits in the two's complement binary representation of the specified long value.
Syntax
public static long reverse(long i)
Parameters
i |
Specify the value to be reversed. |
Return Value
Returns the value obtained by reversing order of the bits in the specified long value.
Exception
NA.
Example:
In the example below, the java.lang.Long.reverse() method returns the value obtained by reversing order of the bits in the given long value.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating a long value long x = 100; //printing value of x, its binary representation //and reversing order of the bits System.out.println("The values of x is: " + x); System.out.print("The binary representation of x is: "); System.out.println(Long.toBinaryString(x)); System.out.print("After reversing : "); System.out.println(Long.reverse(x)); } }
The output of the above code will be:
The values of x is: 100 The binary representation of x is: 1100100 After reversing : 2738188573441261568
❮ Java.lang - Long