Java: Convert from BigInteger to int
Use Number.intValue:
BigInteger bigInt = ...
int i = bigInt.intValue()
Note that this simply discards all but the lowest 32 bits. If the BigInteger is outside of the range −2,147,483,648…2,147,483,647 the conversion my have unexpected results.
| BigInteger | intValue() |
|---|---|
| 1,000 | 1,000 |
| 2,147,483,647 | 2,147,483,647 |
| 2,147,483,648 | −2,147,483,648 |
| 2,147,483,649 | −2,147,483,647 |
| 4,294,967,296 | 0 |
| 10,000,000,000 | 1,410,065,408 |
| −10,000,000,000 | −1,410,065,408 |
Comments
Be the first to comment!