/** * Returns a new {@code BigInteger} which has the same binary representation * as {@code this} but with the bit at position n cleared. The result is * equivalent to {@code this & ~(2^n)}. * <p> * <b>Implementation Note:</b> Usage of this method is not recommended as * the current implementation is not efficient. * * @param n * position where the bit in {@code this} has to be cleared. * @return {@code this & ~(2^n)}. * @throws ArithmeticException * if {@code n < 0}. */ public static BigInteger ClearBit(BigInteger value, int n) { if (TestBit(value, n)) { return(BitLevel.FlipBit(value, n)); } return(value); }
/** * Returns a new {@code BigInteger} which has the same binary representation * as {@code this} but with the bit at position n flipped. The result is * equivalent to {@code this ^ 2^n}. * <p> * <b>Implementation Note:</b> Usage of this method is not recommended as * the current implementation is not efficient. * * @param n * position where the bit in {@code this} has to be flipped. * @return {@code this ^ 2^n}. * @throws ArithmeticException * if {@code n < 0}. */ public static BigInteger FlipBit(BigInteger value, int n) { if (n < 0) { // math.15=Negative bit address throw new ArithmeticException(Messages.math15); //$NON-NLS-1$ } return(BitLevel.FlipBit(value, n)); }