byte[] bytes = {65, 66, 67}; BitSet bitSet = BitSet.valueOf(bytes); System.out.println(bitSet); // Output: {0, 2, 4, 65, 66, 67}
byte[] bytes = {65, 66, 67, 68, 69}; BitSet bitSet = BitSet.valueOf(bytes, 1, 3); System.out.println(bitSet); // Output: {2, 65, 66}In both examples, the java.util package library is used.