Use the reverse()
Method - Part 2
In this step, we will use the reverse()
method on a negative long
value. The process will be the same as that in step 2, but we will use a negative value. We will print the original value and its binary representation using the toBinaryString()
method. Then, we will print the new value obtained by reversing the binary representation of the original value using the reverse()
method.
long number = -12345L;
System.out.println("Original Number: " + number);
System.out.println("Binary Representation: " + Long.toBinaryString(number));
long reversedNumber = Long.reverse(number);
System.out.println("Number After Reversing: " + reversedNumber);