Package java.math

Examples of java.math.BigInteger.testBit()


        BigInteger midpoint;
        boolean remainder;
        if (left.compareTo(right) < 0)
        {
            BigInteger sum = left.add(right);
            remainder = sum.testBit(0);
            midpoint = sum.shiftRight(1);
        }
        else
        {
            BigInteger max = TWO.pow(sigbits);
View Full Code Here


        else
        {
            BigInteger max = TWO.pow(sigbits);
            // wrapping case
            BigInteger distance = max.add(right).subtract(left);
            remainder = distance.testBit(0);
            midpoint = distance.shiftRight(1).add(left).mod(max);
        }
        return Pair.create(midpoint, remainder);
    }
View Full Code Here

    byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    int aSign = 1;
    int number = -7;
    BigInteger aNumber = new BigInteger(aSign, aBytes);
    try {
      aNumber.testBit(number);
      fail("ArithmeticException has not been caught");
    } catch (ArithmeticException e) {
      assertEquals("Improper exception message", "Negative bit address",
          e.getMessage());
    }
View Full Code Here

  public void testTestBitNegative1() {
    byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    int aSign = -1;
    int number = 7;
    BigInteger aNumber = new BigInteger(aSign, aBytes);
    assertTrue(aNumber.testBit(number));
  }

  /**
   * testBit(int n) of a positive n.
   */
 
View Full Code Here

  public void testTestBitNegative2() {
    byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    int aSign = -1;
    int number = 45;
    BigInteger aNumber = new BigInteger(aSign, aBytes);
    assertTrue(!aNumber.testBit(number));
  }

  /**
   * testBit(int n) of a positive n, n > bitLength().
   */
 
View Full Code Here

  public void testTestBitNegative3() {
    byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    int aSign = -1;
    int number = 300;
    BigInteger aNumber = new BigInteger(aSign, aBytes);
    assertTrue(aNumber.testBit(number));
  }

  /**
   * testBit(int n) of a positive number.
   */
 
View Full Code Here

  public void testTestBitPositive1() {
    byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    int aSign = 1;
    int number = 7;
    BigInteger aNumber = new BigInteger(aSign, aBytes);
    assertTrue(!aNumber.testBit(number));
  }

  /**
   * testBit(int n) of a positive number.
   */
 
View Full Code Here

  public void testTestBitPositive2() {
    byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    int aSign = 1;
    int number = 45;
    BigInteger aNumber = new BigInteger(aSign, aBytes);
    assertTrue(aNumber.testBit(number));
  }

  /**
   * testBit(int n) of a positive number, n > bitLength().
   */
 
View Full Code Here

  public void testTestBitPositive3() {
    byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    int aSign = 1;
    int number = 300;
    BigInteger aNumber = new BigInteger(aSign, aBytes);
    assertTrue(!aNumber.testBit(number));
  }
}
View Full Code Here

        byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
        int aSign = 1;
        int number = -7;
        BigInteger aNumber = new BigInteger(aSign, aBytes);
        try {
            aNumber.testBit(number);
            fail("ArithmeticException has not been caught");
        } catch (ArithmeticException e) {
            assertEquals("Improper exception message", "Negative bit address", e.getMessage());
        }
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.