BigInteger num = new BigInteger("25"); if (num.testBit(4)) { System.out.println("4th bit is set."); } else { System.out.println("4th bit is not set."); }
BigInteger num = new BigInteger("1311768467294899695"); if (num.testBit(1)) { System.out.println("1st bit is set."); } else { System.out.println("1st bit is not set."); }Output: 1st bit is set. The package library for BigInteger is java.math.