Java BigInteger bitLength() Method

The bitLength() method of Java BigInteger class returns an int value which corresponds to the number of bits in the minimal two's-complement representation of this BigInteger, excluding a sign bit.

Syntax:

Returns:

This method returns number of bits in the minimal two's-complement representation of this BigInteger, excluding a sign bit.

Note:For positive BigIntegers, this is equivalent to the number of bits in the ordinary binary representation. It Computes (ceil (log2(this <0 " "this: this+1))).

Example

Test it Now

Output:

Result of bitLength operation on 8 is 4
Result of bitLength operation on -9 is 4

Next TopicJava BigInteger




Latest Courses