Returns a string of the bits of a bitset Starts from the end of the bitset and prints left to right moving to lower bits - Java java.util

Java examples for java.util:BitSet

Description

Returns a string of the bits of a bitset Starts from the end of the bitset and prints left to right moving to lower bits

Demo Code


//package com.java2s;
import java.util.BitSet;

public class Main {
    /**/*from w  w  w. j av  a  2  s .  c o m*/
     * Returns a string of the bits of a bitset <br>
     * Starts from the end of the bitset and prints 
     * left to right moving to lower bits
     * 
     * @param bs BitSet to return a string for
     * @return A String containing the bits
     */
    public static String bitSetToString(BitSet bs) {
        String bitSetStr = new String();
        for (int i = (Byte.SIZE - 1); i >= 0; i--) {
            bitSetStr += (bs.get(i) ? 1 : 0);
        }
        return bitSetStr;
    }
}

Related Tutorials