Java BitSet stringToBitSet(String sbits)

Here you can find the source of stringToBitSet(String sbits)

Description

Converts a string into a BitSet.

License

Open Source License

Parameter

Parameter Description
sbits The string to convert.

Return

BitSet representing the binary value.

Declaration

public static BitSet stringToBitSet(String sbits) 

Method Source Code

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

import java.util.BitSet;

public class Main {
    /**//from ww  w.ja v  a  2s  .com
     * Converts a string into a BitSet. 
     * The first character is the most significant bit. 
     * a '1' character is converted to true. 
     * Every other character is converted to false.
     * 
     * @param sbits The string to convert.
     * @return BitSet representing the binary value.
     */
    public static BitSet stringToBitSet(String sbits) {
        BitSet bits = new BitSet(sbits.length());

        for (int i = sbits.length() - 1; i >= 0; i--) {
            bits.set(sbits.length() - 1 - i, (sbits.charAt(i) == '1'));
        }

        return bits;
    }
}

Related

  1. shiftLeft(BitSet s, int length)
  2. shiftLeft(BitSet src, int offset)
  3. shiftRight(BitSet bitset, int n)
  4. storeCharSet(BitSet stored, String... validCharStrings)
  5. strArrToBitSet(String stringArray)
  6. stripToCommonChars(char[] ac, BitSet commonChars)
  7. toArray(BitSet bitset, int size)
  8. toBitSet(byte[] array)
  9. toBitSet(byte[] bytes)