Example usage for java.util BitSet set

List of usage examples for java.util BitSet set

Introduction

In this page you can find the example usage for java.util BitSet set.

Prototype

public void set(int bitIndex) 

Source Link

Document

Sets the bit at the specified index to true .

Usage

From source file:org.efaps.admin.datamodel.attributetype.BitEnumType.java

/**
 * @param _bitIndex bitindex the integer value is wanted for
 * @return integer value representing the bitindex
 *///from   w w w  .  jav a2 s . c om
public static int getInt4Index(final int _bitIndex) {
    final BitSet bitSet = new BitSet(_bitIndex + 1);
    bitSet.set(_bitIndex);
    int ret = 0;
    for (int i = 0; i < bitSet.length(); ++i) {
        ret += bitSet.get(i) ? 1 << i : 0;
    }
    return ret;
}

From source file:Main.java

public static BitSet fromByteArray(byte[] bytes) {
    if (bytes == null) {
        return new BitSet();
    }//from  ww  w  .  java2 s  .c o  m
    BitSet bits = new BitSet();
    for (int i = 0; i < bytes.length * 8; i++) {
        if ((bytes[(bytes.length) - (i / 8) - 1] & (1 << (i % 8))) > 0) {
            bits.set(i);
        }
    }
    return bits;
}

From source file:Main.java

/**
 * Converts a binary representation of a Bitmap field
 * into a Java BitSet/* w  w w  .java  2 s.  c  o  m*/
 * @param b - binary representation
 * @param offset - staring offset
 * @param bitZeroMeansExtended - true for ISO-8583
 * @return java BitSet object
 */
public static BitSet byte2BitSet(byte[] b, int offset, boolean bitZeroMeansExtended) {
    int len = bitZeroMeansExtended ? ((b[offset] & 0x80) == 0x80 ? 128 : 64) : 64;
    BitSet bmap = new BitSet(len);
    for (int i = 0; i < len; i++)
        if (((b[offset + (i >> 3)]) & (0x80 >> (i % 8))) > 0)
            bmap.set(i + 1);
    return bmap;
}

From source file:Main.java

/**
 * Converts a binary representation of a Bitmap field
 * into a Java BitSet/*from  w w w  . j av a  2 s.c  o  m*/
 * @param b - binary representation
 * @param offset - staring offset
 * @param maxBits - max number of bits (supports 64,128 or 192)
 * @return java BitSet object
 */
public static BitSet byte2BitSet(byte[] b, int offset, int maxBits) {
    int len = maxBits > 64 ? ((b[offset] & 0x80) == 0x80 ? 128 : 64) : maxBits;

    if (maxBits > 128 && b.length > offset + 8 && (b[offset + 8] & 0x80) == 0x80) {
        len = 192;
    }
    BitSet bmap = new BitSet(len);
    for (int i = 0; i < len; i++)
        if (((b[offset + (i >> 3)]) & (0x80 >> (i % 8))) > 0)
            bmap.set(i + 1);
    return bmap;
}

From source file:Main.java

/**
 * Converts a binary representation of a Bitmap field
 * into a Java BitSet//from w w  w .j a  v a2s . c  o  m
 * @param bmap - BitSet
 * @param b - hex representation
 * @param bitOffset - (i.e. 0 for primary bitmap, 64 for secondary)
 * @return java BitSet object
 */
public static BitSet byte2BitSet(BitSet bmap, byte[] b, int bitOffset) {
    int len = b.length << 3;
    for (int i = 0; i < len; i++)
        if (((b[i >> 3]) & (0x80 >> (i % 8))) > 0)
            bmap.set(bitOffset + i + 1);
    return bmap;
}

From source file:Main.java

/**
 * Converts an ASCII representation of a Bitmap field
 * into a Java BitSet//from  ww  w  .j av a 2  s .  c o m
 * @param b - hex representation
 * @param offset - starting offset
 * @param bitZeroMeansExtended - true for ISO-8583
 * @return java BitSet object
 */
public static BitSet hex2BitSet(byte[] b, int offset, boolean bitZeroMeansExtended) {
    int len = bitZeroMeansExtended ? ((Character.digit((char) b[offset], 16) & 0x08) == 8 ? 128 : 64) : 64;
    BitSet bmap = new BitSet(len);
    for (int i = 0; i < len; i++) {
        int digit = Character.digit((char) b[offset + (i >> 2)], 16);
        if ((digit & (0x08 >> (i % 4))) > 0)
            bmap.set(i + 1);
    }
    return bmap;
}

From source file:Main.java

/**
 * Converts an ASCII representation of a Bitmap field
 * into a Java BitSet/*from w w  w . j a  va 2s  . c  o m*/
 * @param b - hex representation
 * @param offset - starting offset
 * @param maxBits - max number of bits (supports 8, 16, 24, 32, 48, 52, 64,.. 128 or 192)
 * @return java BitSet object
 */
public static BitSet hex2BitSet(byte[] b, int offset, int maxBits) {
    int len = maxBits > 64 ? ((Character.digit((char) b[offset], 16) & 0x08) == 8 ? 128 : 64) : maxBits;
    BitSet bmap = new BitSet(len);
    for (int i = 0; i < len; i++) {
        int digit = Character.digit((char) b[offset + (i >> 2)], 16);
        if ((digit & (0x08 >> (i % 4))) > 0) {
            bmap.set(i + 1);
            if (i == 65 && maxBits > 128)
                len = 192;
        }
    }
    return bmap;
}

From source file:Main.java

public static BitSet toBitSet(byte[] array) {
    BitSet bitSet = new BitSet(8 * array.length);

    for (int byteNo = 0; byteNo < array.length; byteNo++) {
        byte b = array[byteNo];

        for (int bitNo = 0; bitNo < 8; bitNo++) {
            if ((b & byteMask(bitNo)) != 0) {
                bitSet.set(8 * byteNo + bitNo);
            }//from   w  w  w  .j ava 2s  . c  o m
        }
    }

    return bitSet;
}

From source file:Main.java

/**
 * Converts an ASCII representation of a Bitmap field
 * into a Java BitSet/* w ww . j a va2 s . co m*/
 * @param bmap - BitSet
 * @param b - hex representation
 * @param bitOffset - (i.e. 0 for primary bitmap, 64 for secondary)
 * @return java BitSet object
 */
public static BitSet hex2BitSet(BitSet bmap, byte[] b, int bitOffset) {
    int len = b.length << 2;
    for (int i = 0; i < len; i++) {
        int digit = Character.digit((char) b[i >> 2], 16);
        if ((digit & (0x08 >> (i % 4))) > 0)
            bmap.set(bitOffset + i + 1);
    }
    return bmap;
}

From source file:ws.moor.bt.util.ByteUtil.java

public static BitSet toBitSet(byte[] bytes) {
    BitSet result = new BitSet();
    for (int i = 0; i < bytes.length * 8; i++) {
        if ((bytes[i / 8] & (1 << (7 - (i % 8)))) != 0) {
            result.set(i);
        }/*from   w w  w .j  av  a2  s .  co  m*/
    }
    return result;
}