Java BitSet toBitSet(byte[] bytes)

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

Description

Convert a byte array into a bit set.

License

Open Source License

Parameter

Parameter Description
bytes The byte array to be converted into a bit set

Return

The equivalent bit set

Declaration

public static BitSet toBitSet(byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.BitSet;

public class Main {
    /**//from w  ww . j a  v  a 2s  . c  om
     * Convert a byte array into a bit set.
     *
     * @param bytes The byte array to be converted into a bit set
     * @return The equivalent bit set
     */
    public static BitSet toBitSet(byte[] bytes) {
        BitSet bs = new BitSet();
        for (int i = 0; i < bytes.length * 8; i++) {
            if ((bytes[i / 8] & (1 << (7 - (i % 8)))) > 0)
                bs.set(i, true);
            else
                bs.set(i, false);
        }
        return bs;
    }
}

Related

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