BigInteger clearBit() Method in Java
Prerequisite: BigInteger Basics
The clearBit() method returns a BigInteger which is used to clear a particular bit position in a BigInteger. The bit at index n of binary representation of BigInteger will be cleared means converted to zero. Mathematically we can say that it is used to calculate this & ~(1<<n).
public BigInteger clearBit(int n)
Parameter: The method takes one parameter n which refers to the index of the bit needed to be cleared.
Return Value: The method returns the BigInteger after clearing the bit position n.
Throws: The method might throw an ArithmeticException when n is negative.
Input: value = 2300, index = 3 Output: 2292 Explanation: Binary Representation of 2300 = 100011111100 bit at index 3 is 1 so clear the bit at index 3 Now Binary Representation becomes 100011110100 and Decimal equivalent of 100011110100 is 2292 Input: value = 5482549, index = 0 Output: 5482548
Below program illustrate the clearBit(index) method of BigInteger().
After applying clearbit at index 0 of 5482549 New Value is 5482548
My Personal Notes arrow_drop_up
Please Login to comment...