Java lang.Long.reverse() method in Java with Examples Last Updated : 23 May, 2019 Comments Improve Suggest changes Like Article Like Report java.lang.Long.reverse() is a built-in function in Java which 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 num) Parameter : num - the number passed Returns : the value obtained by reversing the order of the bits in the two's complement binary representation of the specified long value. Examples: Input : 254 Output : 9151314442816847872 Input : 8 Output : 1152921504606846976 The program below illustrates the java.lang.Long.reverse() function: Program 1 : CPP // Java program that demonstrates the // Long.reverse() function // include lang package import java.lang.*; public class GFG { public static void main(String[] args) { long l = 8; System.out.println("The number after reversing bit= " + Long.reverse(l)); l = 254; System.out.println("The number after reversing bit= " + Long.reverse(l)); } } Output: The number after reversing bit= 1152921504606846976 The number after reversing bit= 9151314442816847872 Program 2 : When a negative number is passed Java // Java program that demonstrates the // Long.reverse() function // negative number // include lang package import java.lang.*; public class GFG { public static void main(String[] args) { long l = -8; System.out.println("The number after reversing bit= " + Long.reverse(l)); l = -254; System.out.println("The number after reversing bit= " + Long.reverse(l)); } } Output: The number after reversing bit= 2305843009213693951 The number after reversing bit= 4683743612465315839 Program 3 : When a decimal number is passed Java // Java program that demonstrates the // Long.reverse() function // decimal number // include lang package import java.lang.*; public class GFG { public static void main(String[] args) { System.out.println("The number after reversing bit= " + Long.reverse(11.34)); } } Output: prog.java:16: error: incompatible types: possible lossy conversion from double to long + Long.reverse(11.34)); Program 4 : When a string number is passed Java // Java program that demonstrates the // Long.reverse() function // string number // include lang package import java.lang.*; public class GFG { public static void main(String[] args) { System.out.println("The number after reversing bit= " + Long.reverse("12")); } } Output: prog.java:16: error: incompatible types: String cannot be converted to long + Long.reverse("12")); Comment More infoAdvertise with us Next Article Java lang.Long.reverse() method in Java with Examples gopaldave Follow Improve Article Tags : Java Java-lang package Java-Functions java-Long Practice Tags : Java Similar Reads Java lang.Long.numberOfLeadingZeros() method in Java with Examples java.lang.Long.numberOfLeadingZeros() is a built-in function in Java which returns the number of leading zero bits to the left of the highest order set bit. In simple terms, it returns the (64-position) where position refers to the highest order set bit from the right. If the number does not contain 3 min read Java lang.Long.byteValue() method in Java with Examples java.lang.Long.byteValue() is a built-in function in Java that returns the value of this Long as a byte. Syntax: public byte byteValue() Parameters: The function does not accept any parameter. Return : This method returns the numeric value represented by this object after conversion to byte type. Ex 3 min read Java Guava | Lists.reverse() method with Examples Guava's Lists.reverse() method accepts a list as a parameter and returns a reversed view of the list passed as the parameter. If the specified list is random access, then the returned list is also random-access. For example: Lists.reverse(Arrays.asList(1, 2, 3)) returns a list containing 3, 2, 1. Sy 2 min read Java lang.Long.lowestOneBit() method in Java with Examples java.lang.Long.lowestOneBit() is a built-in method in Java which first convert the number to Binary, then it looks for first set bit present at the lowest position then it reset rest of the bits and then returns the value. In simple language, if the binary expression of a number contains a minimum o 3 min read Java Guava | Longs.lastIndexOf() method with Examples The lastIndexOf() method of Longs Class in Guava library is used to find the last index of the given long value in a long array. This long value to be searched and the long array in which it is to be searched, both are passed as a parameter to this method. It returns an integer value which is the la 3 min read Number.longValue() method in java with examples The Number.longValue() is an inbuilt method in Java of java.lang package. This method is used to convert any numeric value into a long type. This may involve rounding or truncation.What is longValue()?The longValue() method returns the value of a number after converting it to the long data type. Som 2 min read LongBuffer rewind() method in Java with Examples The rewind() method of java.nio.LongBuffer Class is used to rewind this buffer. By rewinding this Buffer, the following actions are taken: Current position is set to zero the mark is discarded, if any, but the mark value is unchanged. Syntax: public LongBuffer rewind() Parameter: This method do not 2 min read Collections.reverse() Method in Java with Examples The reverse() method of the Collections class, as the name suggests, is used to reverse the order of elements in a list. Note: It does not sort the elements, it simply reverses their current order.This class is present in java.util package so the syntax is as follows:import java.util.Collections;Col 3 min read Comparator reversed() method in Java with examples The reversed() method of Comparator Interface in Java returns a comparator that imposes the reverse ordering of this comparator. If you use sort method of the array and passes this comparator after applying the reversed method then it will sort the array in reverse order. Syntax: default Comparator 2 min read StringBuffer reverse() Method in Java with Examples The Java.lang.StringBuffer.reverse() is an inbuilt method that is used to reverse the characters in the StringBuffer. The method causes this character sequence to be replaced by the reverse of the sequence. Syntax: public StringBuffer reverse() Parameters: NA Return Value: The method returns the Str 2 min read Like