Example usage for java.math BigInteger setBit

List of usage examples for java.math BigInteger setBit

Introduction

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

Prototype

public BigInteger setBit(int n) 

Source Link

Document

Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit set.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte[] bytes = new byte[] { 0x1, 0x00, 0x00 };
    BigInteger bi = new BigInteger(bytes);
    bi = bi.setBit(3);

}

From source file:Main.java

public static void main(String[] args) {

    BigInteger bi1 = new BigInteger("7");

    // perform setbit operation on bi1 using index 3
    BigInteger bi2 = bi1.setBit(3);

    System.out.println(bi2);//from  w  w  w . java 2s.c om
}

From source file:Main.java

public static BigInteger sumRights(int[] rights) {
    BigInteger num = new BigInteger("0");
    for (int i = 0; i < rights.length; i++) {
        num = num.setBit(rights[i]);
    }/*from   w ww . j  a v  a  2s .  co m*/
    return num;
}

From source file:Main.java

public static BigInteger sumRights(String[] rights) {
    BigInteger num = new BigInteger("0");
    for (int i = 0; i < rights.length; i++) {
        num = num.setBit(Integer.parseInt(rights[i]));
    }//from  ww  w.  ja va  2  s .  com
    return num;
}

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 w  w w  .ja va 2  s .  c o 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.google.uzaygezen.core.LongBitVector.java

@Override
public BigInteger toBigInteger() {
    final BigInteger result;
    if (data >= 0) {
        result = BigInteger.valueOf(data);
    } else {/*w w w  . j ava2 s  .  co  m*/
        BigInteger missingLowestBit = BigInteger.valueOf(data >>> 1).shiftLeft(1);
        if ((data & 1) == 1) {
            result = missingLowestBit.setBit(0);
        } else {
            result = missingLowestBit;
        }
    }
    return result;
}

From source file:com.google.uzaygezen.core.BitVectorTest.java

private void checkCopyFromToBigInteger(Function<Integer, BitVector> factory) {
    for (int j = 0; j < 128; j++) {
        BitVector b = factory.apply(j);/*from   w  w w . j  a va  2  s .c  o m*/
        boolean[] bits = new boolean[b.size()];
        for (int k = 0; k < b.size(); ++k) {
            bits[k] = random.nextBoolean();
        }
        BigInteger expected = BigInteger.ZERO;
        for (int k = 0; k < b.size(); ++k) {
            b.set(k, bits[k]);
            if (bits[k]) {
                expected = expected.setBit(k);
            }
        }
        Assert.assertEquals(expected, b.toBigInteger());
        BitVector revived = factory.apply(j);
        revived.copyFrom(expected);
        Assert.assertEquals(b, revived);
    }
}

From source file:org.openhab.binding.ulux.internal.ump.messages.ActivateMessage.java

@Override
protected void addData(final ByteBuffer buffer) {
    BigInteger flags = BigInteger.valueOf(0);

    if (isActive()) {
        flags = flags.setBit(0);
    } else {//  w  w w . ja  v  a  2  s  .co m
        flags = flags.setBit(1);
    }

    // flags
    buffer.put(flags.byteValue());

    // reserved
    buffer.put((byte) 0x00);
}

From source file:org.openhab.binding.ulux.internal.ump.messages.AudioStopMessage.java

@Override
protected void addData(final ByteBuffer buffer) {
    BigInteger flags = BigInteger.valueOf(0);

    if (stopNormal) {
        flags = flags.setBit(0);
    }//  www .j  a va  2s. c o  m
    if (stopAlarm) {
        flags = flags.setBit(1);
    }

    // flags
    buffer.put(flags.byteValue());

    // reserved
    buffer.put((byte) 0x00);
}

From source file:org.openhab.binding.ulux.internal.ump.messages.ControlMessage.java

@Override
protected void addData(final ByteBuffer buffer) {
    BigInteger controlFlags = BigInteger.valueOf(0);

    // TODO this.lockMode
    // TODO this.backgroundLight

    if (this.i2cPlugAndPlay) {
        controlFlags = controlFlags.setBit(31);
    }//from   ww w. j a  va 2 s . c om
    if (this.i2cHumidityChangeRequest) {
        controlFlags = controlFlags.setBit(25);
    }
    if (this.i2cTemperatureChangeRequest) {
        controlFlags = controlFlags.setBit(24);
    }
    if (this.motionSensorChangeRequest) {
        controlFlags = controlFlags.setBit(11);
    }
    if (this.keepAlive) {
        controlFlags = controlFlags.setBit(10);
    }
    if (this.changeFilter) {
        controlFlags = controlFlags.setBit(9);
    }
    if (this.frameAcknowledgement) {
        controlFlags = controlFlags.setBit(8);
    }
    if (this.volumeChangeRequest) {
        controlFlags = controlFlags.setBit(5);
    }
    if (this.pageChangeRequest) {
        controlFlags = controlFlags.setBit(4);
    }
    if (this.audioActiveChangeRequest) {
        controlFlags = controlFlags.setBit(3);
    }
    if (this.displayActiveChangeRequest) {
        controlFlags = controlFlags.setBit(2);
    }
    if (this.proximitySensorChangeRequest) {
        controlFlags = controlFlags.setBit(1);
    }
    if (this.lightSensorChangeRequest) {
        controlFlags = controlFlags.setBit(0);
    }

    buffer.putInt(controlFlags.intValue());
}