Example usage for java.math BigInteger testBit

List of usage examples for java.math BigInteger testBit

Introduction

In this page you can find the example usage for java.math BigInteger testBit.

Prototype

public boolean testBit(int n) 

Source Link

Document

Returns true if and only if the designated bit is set.

Usage

From source file:com.artivisi.iso8583.Message.java

public void calculateBitmap() {
    LOGGER.debug("Number of active Data Element [{}]", dataElementContent.size());
    BigInteger bitmap = BigInteger.ZERO.setBit(128);
    for (Integer de : dataElementContent.keySet()) {
        LOGGER.debug("Set active flag for Data Element [{}]", de);
        if (de > 64) {
            bitmap = bitmap.setBit(128 - 1);
        }/*from www. j a  va2 s.  co m*/
        bitmap = bitmap.setBit(128 - de);
    }
    LOGGER.debug("Final bitmap bin : [{}]", bitmap.toString(2).substring(1));
    LOGGER.debug("Final bitmap hex : [{}]", bitmap.toString(16).substring(1));
    setPrimaryBitmapStream(StringUtils.rightPad(bitmap.toString(16).substring(1, 16), 16, "0"));
    if (bitmap.testBit(128 - 1)) {
        setSecondaryBitmapStream(StringUtils.rightPad(bitmap.toString(16).substring(17), 16, "0"));
    }
}

From source file:com.amazon.carbonado.repo.jdbc.LoggingPreparedStatement.java

private void logStatement() {
    String statement = mSQL;//from   w w w.j ava  2  s.  c om

    Object[] params;
    BigInteger setParams;
    if ((params = mParams) != null && (setParams = mSetParams) != BigInteger.ZERO) {
        int length = setParams.bitLength();
        StringBuilder b = new StringBuilder(statement.length() + length * 10);
        b.append(statement);
        b.append(" -- ");
        boolean any = false;
        for (int i = 0; i < length; i++) {
            if (setParams.testBit(i)) {
                if (any) {
                    b.append(", [");
                } else {
                    b.append('[');
                    any = true;
                }
                b.append(i);
                b.append("]=");
                b.append(params[i]);
            }
        }
        statement = b.toString();
    }

    mLog.debug(statement);
}

From source file:org.tomahawk.libtomahawk.resolver.ScriptResolver.java

public void reportCapabilities(int in) {
    BigInteger bigInt = BigInteger.valueOf(in);
    if (bigInt.testBit(0)) {
        mBrowsable = true;/* w  w  w  . ja  v  a 2 s  .c  om*/
        collection();
    }
    if (bigInt.testBit(1)) {
        mPlaylistSync = true;
    }
    if (bigInt.testBit(2)) {
        mAccountFactory = true;
    }
    if (bigInt.testBit(3)) {
        mUrlLookup = true;
    }
    if (bigInt.testBit(4)) {
        mConfigTestable = true;
    }
}

From source file:cc.redberry.core.number.Complex.java

@Override
public Complex pow(BigInteger exponent) {
    if (exponent.compareTo(BigInteger.ZERO) < 0)
        return reciprocal().pow(exponent.negate());

    Complex result = Complex.ONE;/*w w  w .j  a  v a2 s .  com*/
    Complex k2p = this;
    while (!BigInteger.ZERO.equals(exponent)) {
        if (exponent.testBit(0))
            result = result.multiply(k2p);

        k2p = k2p.multiply(k2p);
        exponent = exponent.shiftRight(1);
    }

    return result;
}