return new BitVector(values);
}
+ /**
+ * Changes a single Bit using the given operation. This can be used to set, clear or flip bits.
+ *
+ * @param msbIndex index of the MSB to be changed
+ * @param singleBitOperation the operation to perform on that Bit
+ * @return the resulting, new BitVektor
+ */
+ public BitVector withBitChanged(int msbIndex, UnaryOperator<Bit> singleBitOperation)
+ {
+ Bit[] newBits = bits.clone();
+ newBits[msbIndex] = singleBitOperation.apply(newBits[msbIndex]);
+ return new BitVector(newBits);
+ }
+
/**
* Iterate over the {@link Bit}s of the BitVector <b>from MSB to LSB</b> (left to right).
*/
}
};
}
-
- public static void main(String[] args)
- {
-// System.out.println(new BigInteger(new byte[] { 0b1000000, 0b00000000 }).toString(2));
-// System.out.println(BitVector.SINGLE_1.concat(BitVector.of(Bit.ZERO, 14)).getUnsignedValue().toString(2));
- System.out.println(new BigInteger(new byte[] { 0b0000000, 0b00000101 }).toString(2));
- System.out.println(BitVector.of(Bit.ZERO, 7).concat(BitVector.of(Bit.ONE, Bit.ZERO, Bit.ONE)).getUnsignedValue().toString(2));
- }
}