BigInteger longValue() Method in Java Last Updated : 07 Oct, 2022 Comments Improve Suggest changes Like Article Like Report The java.math.BigInteger.longValue() converts this BigInteger to a long value. If the value return by this function is too big to fit into long value, then it will return only the low-order 64 bits. There is chance that this conversion can lose information about the overall magnitude of the BigInteger value. This method can also return the result with opposite sign. Syntax: public long longValue() Returns: The method returns a long value which represents long value for this BigInteger. Examples: Input: BigInteger1=3214558191 Output: 3214558191 Explanation: BigInteger1.longValue()=3214558191. Input: BigInteger1=32145535361361525377 Output: -4747952786057577855 Explanation: BigInteger1.longValue()=-4747952786057577855. This BigInteger is too big for longValue so it is returning lower 64 bit. Example 1: Below programs illustrate longValue() method of BigInteger class Java // Java program to demonstrate longValue() method of BigInteger import java.math.BigInteger; public class GFG { public static void main(String[] args) { // Creating 2 BigInteger objects BigInteger b1, b2; b1 = new BigInteger("3214553537"); b2 = new BigInteger("76137217351"); // apply longValue() method long longValueOfb1 = b1.longValue(); long longValueOfb2 = b2.longValue(); // print longValue System.out.println("longValue of " + b1 + " : " + longValueOfb1); System.out.println("longValue of " + b2 + " : " + longValueOfb2); } } Output:longValue of 3214553537 : 3214553537 longValue of 76137217351 : 76137217351 Example 2: when return long is too big for long value. Java // Java program to demonstrate longValue() method of BigInteger import java.math.BigInteger; public class GFG { public static void main(String[] args) { // Creating 2 BigInteger objects BigInteger b1, b2; b1 = new BigInteger("32145535361361525377"); b2 = new BigInteger("7613721535372632367351"); // apply longValue() method long longValueOfb1 = b1.longValue(); long longValueOfb2 = b2.longValue(); // print longValue System.out.println("longValue of " + b1 + " : " + longValueOfb1); System.out.println("longValue of " + b2 + " : " + longValueOfb2); } } Output:longValue of 32145535361361525377 : -4747952786057577855 longValue of 7613721535372632367351 : -4783767069412450057 Reference: BigInteger longValue() Docs Comment More infoAdvertise with us Next Article BigInteger longValue() Method in Java A AmanSingh2210 Follow Improve Article Tags : Java java-basics Java-Functions java-math Java-BigInteger Java-math-package +2 More Practice Tags : JavaJava-BigInteger Similar Reads BigDecimal longValue() Method in Java The java.math.BigDecimal.longValue() is an in-built function which converts this BigDecimal to a long value. This function discards any fractional part of this BigDecimal. The function returns only the lower-order 64 bits when the result of the conversion is too big to be represented as a long value 2 min read BigInteger or() method in Java Prerequisite: BigInteger Basics The java.math.BigInteger.or(BigInteger val) method is used to perform bitwise OR of two BigIntegers. One of the BigInteger is passed in parameter and the other on which the function is called. This method returns a negative number if either of the BigIntegers used wit 2 min read BigInteger intValue() Method in Java The java.math.BigInteger.intValue() converts this BigInteger to an integer value. If the value returned by this function is too big to fit into integer value, then it will return only the low-order 32 bits. Further there is chance that this conversion can lose information about the overall magnitude 2 min read BigInteger and() Method in Java The java.math.BigInteger.and(BigInteger val) method returns a BigInteger whose value is bitwise-AND of two BigIntegers. This method returns a negative number if both of the BigIntegers are negative. The and() method applies bitwise-AND operation upon the current bigInteger and bigInteger passed as p 2 min read BigInteger xor() Method in Java Prerequisite: BigInteger Basics The xor(BigInteger val) method returns bitwise-XOR of two bigIntegers. This method returns a negative BigInteger if and only if exactly one of the current bigInteger and the bigInteger passed in parameter id negative. The xor() method of BigInteger class apply bitwise 2 min read BigInteger pow() Method in Java The java.math.BigInteger.pow(int exponent) method is used to calculate a BigInteger raise to the power of some other number passed as exponent whose value is equal to (this)exponent. This method performs operation upon the current BigInteger by which this method is called and exponent passed as para 2 min read BigInteger mod() Method in Java The java.math.BigInteger.mod(BigInteger big) method returns a BigInteger whose value is equal to (this BigInteger modfunction big(BigInteger passed as parameter)).In other words we can say that this method returns the value after performing (this % big) step.The mod operation finds the remainder aft 3 min read BigInteger not() Method in Java The java.math.BigInteger.not() method is used to find the bitwise-NOT of a BigInteger. This method returns a negative value if and only if this BigInteger is non-negative. The BigInteger.not() method apply bitwise Not operation upon the current bigInteger. Syntax: public BigInteger not() Parameters: 1 min read BigDecimal longValueExact() Method in Java The java.math.BigDecimal.longValueExact() is an in-built function which converts this BigDecimal to a long value as well as checks for lost information. This function throws Arithmetic Exception if there is any fractional part of this BigDecimal or if the result of the conversion is too big to be re 3 min read BigInteger valueOf() Method in Java The java.math.BigInteger.valueOf(long value) method returns a BigInteger whose value is equal to value of long passed as parameter. This method is static method so It is not necessary to create object of BigInteger class to use this method.we can call this function by BigInteger.valueOf(long value) 2 min read Like