A BitSet is a bit container.
An initial size can be set:
BitSet bs = new BitSet(64);
you can set single bits to true:
bs.set(1);
It grows if needed:
// Bit 68 not available, so it automatically grows bs.set(68);
It can be filled with a byte array or a long array:
byte n = 2; byte t = 4; // Fill the Bitset with a byte array BitSet bs = BitSet.valueOf(new byte[]{n, t}); // Retrieve the byte array from the BitSet byte[] arr = bs.toByteArray(); // Print the byte array returned System.out.println(arr[0] + " " + arr[1]);
It can perform logical operations:
// Define two arrays BitSet bs1 = new BitSet(); BitSet bs2 = new BitSet(); // Set the active bits to 1 bs1.set(3); bs1.set(4); bs2.set(4); // Logical AND operation bs1.and(bs2); // Print the active bits after the logical operation System.out.println(bs1);
Copyright © 2013 Welcome to the website of Davis Fiore. All Rights Reserved.