Java BitSet toBitSet(byte[] array)

Here you can find the source of toBitSet(byte[] array)

Description

to Bit Set

License

BSD License

Declaration

public static BitSet toBitSet(byte[] array) 

Method Source Code

//package com.java2s;
/*//from  www. j  a v a 2 s. c o m
 * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
 *
 * Licensed under the Aduna BSD-style license.
 */

import java.util.BitSet;

public class Main {
    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);
                }
            }
        }

        return bitSet;
    }

    private static byte byteMask(int bitNo) {
        return (byte) (0x80 >>> (bitNo % 8));
    }
}

Related

  1. storeCharSet(BitSet stored, String... validCharStrings)
  2. strArrToBitSet(String stringArray)
  3. stringToBitSet(String sbits)
  4. stripToCommonChars(char[] ac, BitSet commonChars)
  5. toArray(BitSet bitset, int size)
  6. toBitSet(byte[] bytes)
  7. toBitSet(final byte[] bytes)
  8. toBitSet(String data)
  9. toBitSet(String s, int length)