Package java.math

Examples of java.math.BigInteger.testBit()


    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));
    }

    /**
     * testBit(int n) of a negative number
     */
 
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));
    }
}
View Full Code Here

        BigInteger strippedBI = quotAndRem[0];
        HarmonyBigDecimal integralValue = new HarmonyBigDecimal(quotAndRem[0]);
        long resultPrecision = integralValue.precision();
        int i = 1;
        // To strip trailing zeros until the specified precision is reached
        while (!strippedBI.testBit(0)) {
            quotAndRem = strippedBI.divideAndRemainder(TEN_POW[i]);
            if ((quotAndRem[1].signum() == 0) &&
                    ((resultPrecision - i >= mcPrecision)
                    || (newScale - i >= diffScale)) ) {
                resultPrecision -= i;
View Full Code Here

        }
        BigInteger strippedBI = getUnscaledValue();
        BigInteger[] quotAndRem;
       
        // while the number is even...
        while (!strippedBI.testBit(0)) {
            // To divide by 10^i
            quotAndRem = strippedBI.divideAndRemainder(TEN_POW[i]);
            // To look the remainder
            if (quotAndRem[1].signum() == 0) {
                // To adjust the scale
View Full Code Here

                if(fnName.equals(QN_GET_RESOURCE_BY_ABSOLUTE_ID)) {
                   
                    final IntegerValue absoluteIdParam = (IntegerValue)args[0].itemAt(0);
                    BigInteger absoluteId = (BigInteger)absoluteIdParam.toJavaObject(BigInteger.class);
                   
                    final byte resourceType = absoluteId.testBit(0) ? DocumentImpl.BINARY_FILE : DocumentImpl.XML_FILE;
                    absoluteId = absoluteId.shiftRight(1);
                    final int documentId = absoluteId.and(BigInteger.valueOf(0xFFFFFFFF)).intValue();
                    absoluteId = absoluteId.shiftRight(32);
                    final int collectionId = absoluteId.and(BigInteger.valueOf(0xFFFFFFFF)).intValue();
                   
View Full Code Here

    public IRubyObject bn_is_bit_set(IRubyObject n) {
        int pos = RubyNumeric.num2int(n);
        BigInteger val = this.value;
        try {
            if (val.signum() >= 0) {
                return getRuntime().newBoolean(val.testBit(pos));
            } else {
                return getRuntime().newBoolean(val.abs().testBit(pos));
            }
        } catch (ArithmeticException e) {
            throw newBNError(getRuntime(), "invalid pos");
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.