I'm attempting to make a method that does a left shift with wrap around in Java using BitSet
, but I cannot figure out how to get it to do the wrap around. Right now my method just removes the first bit and keeps the rest without adding that first bit to the end.
public static BitSet leftShift(int amount, BitSet b){
BitSet bit2 = new BitSet(b.length());
for(int i = b.length(); i > 0; i--){
bit2.set((i-amount)%b.length(), b.get(i));
}
return bit2;
}