Java BitSet BitString2BitSet(String string)

Here you can find the source of BitString2BitSet(String string)

Description

Converts the given {0,1}-String to a BitSet .

License

Open Source License

Parameter

Parameter Description
string the {0,1}-String to convert

Return

representation of the string

Declaration

public static BitSet BitString2BitSet(String string) 

Method Source Code


//package com.java2s;
/*/*ww  w  .  ja va2s . co m*/
 * Scaffold Hunter
 * Copyright (C) 2006-2008 PG504
 * Copyright (C) 2010-2011 PG552
 * See the file README.txt in the root directory of the Scaffold Hunter
 * source tree for details.
 *
 * Scaffold Hunter is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Scaffold Hunter is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.BitSet;

public class Main {
    /**
     * Converts the given {0,1}-String to a {@link BitSet}.
     * 
     * @param string
     *            the {0,1}-String to convert
     * @return {@link BitSet} representation of the string
     */
    public static BitSet BitString2BitSet(String string) {

        char[] chStr = string.toCharArray();
        BitSet bitset = new BitSet(chStr.length);

        for (int i = 0; i < chStr.length; i++) {
            if (chStr[chStr.length - i - 1] == '1') {
                bitset.set(i);
            }
        }
        return bitset;
    }
}

Related

  1. asArrayWith0s(int max, BitSet bits)
  2. binaryStringToBitSet(String stringRepresentation)
  3. binaryToGray(BitSet binary)
  4. bitsetCopy(BitSet src, int srcOffset, BitSet dest, int destOffset, int length)
  5. bitSetTest(BitSet bitSet, int index)
  6. boolToBitSet(boolean[] bits, int offset, int length)
  7. byte2BitSet(BitSet bmap, byte[] b, int bitOffset)
  8. byteArray2BitSet(byte[] bytes)
  9. bytes2bitset(byte[] bytes, byte nbyte, BitSet bits)