BigInteger testBit() Method in Java Last Updated : 04 Dec, 2018 Comments Improve Suggest changes Like Article Like Report prerequisite : BigInteger Basics The java.math.BigInteger.testBit(index) method returns true if and only if the designated bit is set. This method Computes (this & (1<<n)) != 0). Syntax: public boolean testBit(int n) Parameter: The method takes one parameter n of integer type which refers to the index of the bit that needs to be tested. Return Value: The method returns true if and only if the designated bit is set else it will return false. Exception: The method will throw an ArithmeticException when n is negative. Examples: Input: BigInteger = 2300, n = 4 Output: true Explanation: Binary Representation of 2300 = 100011111100 bit at index 4 is 1 so set it means bit is set so method will return true Input: BigInteger = 5482549 , n = 1 Output: false Below program illustrates the testBit() method of BigInteger. Java // Program to demonstrate the testBit() // method of BigInteger import java.math.*; public class GFG { public static void main(String[] args) { // Creating a BigInteger object BigInteger biginteger = new BigInteger("2300"); // Creating an int i for index int i = 3; boolean flag = biginteger.testBit(i); String result = "The bit at index " + i + " of " + biginteger + " is set = " + flag; // Displaying the result System.out.println(result); } } Output: The bit at index 3 of 2300 is set = true Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#testBit(int) Comment More infoAdvertise with us Next Article BigInteger testBit() Method in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions java-math Java-BigInteger Java-math-package +1 More Practice Tags : JavaJava-BigInteger Similar Reads BigInteger setBit() Method in Java The java.math.BigInteger.setbit(index) method returns a Big-integer whose value is equivalent to this Big-integer with the designated bit set. The method computes (this | (1<<n)). The bit at index n of binary representation of Big-integer will be set means converted to 1. Syntax: public BigInt 2 min read BigInteger toString() Method in Java BigInteger Class offers 2 methods for toString(). toString(int radix): The java.math.BigInteger.toString(int radix) method returns the decimal String representation of this BigInteger in given radix. Radix parameter decides on which number base (Binary, octal, hex etc) it should return the string. I 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 BigInteger shiftRight() Method in Java prerequisite : BigInteger Basics The java.math.BigInteger.shiftRight(int n) method returns a BigInteger whose value is (this >> n). The shift distance, n, may be negative, in which case this method performs a left shift. The shiftRight() method will move each digit in a number's binary represe 2 min read BigInteger signum() Method in Java prerequisite : BigInteger Basics The java.math.BigInteger.signum() method helps us to identify whether a BigInteger is positive or zero or negative. It returns one of the following values depending on the following conditions: returns -1 when number is negativereturns 0 when number is zeroreturns +1 2 min read Like