Java Reference
In-Depth Information
bs1 = bsTemp;
dumpBitset(" ", bs1);
dumpBitset(" ", bs2);
bsTemp = (BitSet) bs1.clone();
bs1.xor(bs2);
dumpSeparator(Math.min(bs1.size(), 16));
dumpBitset("XOR (^) ", bs1);
}
static void dumpBitset(String preamble, BitSet bs)
{
System.out.print(preamble);
int size = Math.min(bs.size(), 16);
for (int i = 0; i < size; i++)
System.out.print(bs.get(i) ? "1" : "0");
System.out.print(" size("+bs.size()+"),
length("+bs.length()+")");
System.out.println();
}
static void dumpSeparator(int len)
{
System.out.print(" ");
for (int i = 0; i < len; i++)
System.out.print("-");
System.out.println();
}
}
WhydidIspecify Math.min(bs.size(), 16) in dumpBitset() ,andpass
a similar expression to dumpSeparator() ? I wanted to display exactly 16 bits and
16 dashes (for aesthetics), and needed to account for a bitset's size being less than 16.
Although this does not happen with the JDK's BitSet class, it might happen with a
non-JDK variant.
When you run this application, it generates the following output:
0000110001100000 size(64), length(11)
0000101101000000 size(64), length(10)
----------------
Search WWH ::




Custom Search