BitSet to Binary String - Java java.util

Java examples for java.util:BitSet

Description

BitSet to Binary String

Demo Code


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

public class Main {
    public static String toBinaryString(BitSet bs) {
        StringBuilder sb = new StringBuilder(bs.length());
        for (int i = bs.length() - 1; i >= 0; i--)
            sb.append(bs.get(i) ? 1 : 0);
        return sb.toString();
    }/*from ww  w  .j ava 2s . c o  m*/
}

Related Tutorials