VOOZH about

URL: https://www.geeksforgeeks.org/java/biginteger-intvalue-method-in-java/

⇱ BigInteger intValue() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

BigInteger intValue() Method in Java

Last Updated : 7 Oct, 2022

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 of the BigInteger value. This method can also return the result with opposite sign. Syntax:

public int intValue()

Returns: The method returns an int value which represents integer value for this BigInteger. Examples:

Input: BigInteger1=32145
Output: 32145
Explanation: BigInteger1.intValue()=32145.

Input: BigInteger1=4326516236135
Output: 1484169063
Explanation: BigInteger1.intValue()=1484169063. This BigInteger is too big for 
intValue so it is returning lower 32 bit.

Example 1:Below programs illustrate intValue() method of BigInteger class 

Output:
intValue of 32145 : 32145
intValue of 7613721 : 7613721

Example 2: when return integer is too big for int value. 

Output:
intValue of 4326516236135 : 1484169063
intValue of 251362466336 : -2040604128

Reference: BigInteger intValue() Docs

Comment