Java BitSet createBitSetFromBinaryString(String bitsAsBinaryString)

Here you can find the source of createBitSetFromBinaryString(String bitsAsBinaryString)

Description

converts a string to a bitset counting all 1's as true and all other characters as false

License

Apache License

Parameter

Parameter Description
bitsAsBinaryString a parameter

Declaration

public static BitSet createBitSetFromBinaryString(String bitsAsBinaryString) 

Method Source Code

//package com.java2s;
/*//  ww w.j av a2 s .com
 *    Copyright 2016 Roche NimbleGen Inc.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import java.util.BitSet;

public class Main {
    /**
     * converts a string to a bitset counting all 1's as true and all other characters as false
     * 
     * @param bitsAsBinaryString
     * @return
     */
    public static BitSet createBitSetFromBinaryString(String bitsAsBinaryString) {
        BitSet bitSet = new BitSet(bitsAsBinaryString.length());

        for (int i = 0; i < bitsAsBinaryString.length(); i++) {
            if (bitsAsBinaryString.substring(i, i + 1).equals("1")) {
                bitSet.set(i, true);
            } else {
                bitSet.set(i, false);
            }
        }

        return bitSet;
    }
}

Related

  1. compare(BitSet a, BitSet b)
  2. copy(BitSet bs)
  3. copyBits(BitSet source, BitSet dest, int fromIndex)
  4. copyBitSetToBitSet(BitSet src, int srcPos, BitSet dest, int destPos, int length)
  5. countLeadingSimilarBits(BitSet a, BitSet b)
  6. createSimpleBitSet(Set setBits)
  7. decode(BitSet encoded, int encodedBitLength)
  8. decodeIndex(final BitSet bs, final long rangePerDimension)
  9. deleteBits(BitSet bs, BitSet bsDelete)