I am looking for an efficient way how to easily convert a BitSet
to a binary string. Let us say that its usual length would be thousands of bits.
For example, lets have this:
BitSet bits = new BitSet(8);
bits.set(1);
bits.set(3);
And this is the desired result:
String result = toBinaryString(bits);
// expected: result = "01010000"
I have some ideas in general (streams, etc.), but there might be some obvious standard method I am just missing.
So this is the most efficient way I have tried so far:
Or other way using more streams: