X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Ftypes%2FBitVector.java;h=4d5f9110d1f0a0d81acb70d6147915a18cd6e7af;hb=668d5f2a864ed026891a5befe628305fe7a77fac;hp=aed0288d93b8efd0a660e3b9dc6b49248036ad1a;hpb=f37f1f93f2c1ceb780f1c7ecab888bcb8f4f8b89;p=Mograsim.git diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVector.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVector.java index aed0288d..4d5f9110 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVector.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVector.java @@ -50,11 +50,11 @@ public final class BitVector implements StrictLogicType, Iterable, Iterable, Iterable, Iterable op) @@ -227,11 +225,11 @@ public final class BitVector implements StrictLogicType, Iterablewith all bits set to null. Use with care! + * Returns a new mutator of the specified length, with all bits set to null. Use with care! */ - public static BitVectorMutator ofWidth(int width) + public static BitVectorMutator ofLength(int length) { - return new BitVectorMutator(new Bit[width]); + return new BitVectorMutator(new Bit[length]); } /** @@ -344,17 +342,17 @@ public final class BitVector implements StrictLogicType, Iterable, Iterableoffset to the right.
- * Therefore offset + other.width() <= this.wdith() needs to be true. + * Therefore offset + other.length() <= this.wdith() needs to be true. * - * @throws ArrayIndexOutOfBoundsException if offset + other.width() > this.width() + * @throws ArrayIndexOutOfBoundsException if offset + other.length() > this.length() * * @see Object#equals(Object) */ @@ -395,7 +393,7 @@ public final class BitVector implements StrictLogicType, Iterable, Iterable= 0; i--) { - if (Bit.ONE == bits[i]) + if (Bit.ONE == bits[bits.length - i - 1]) { - bytes[i / 8] |= 1 << (i % 8); + try + { + bytes[bytes.length - (i / 8) - 1] |= 1 << (i % 8); + } + catch (IndexOutOfBoundsException e) + { + e.printStackTrace(); + } } } return new BigInteger(bytes); @@ -447,6 +452,20 @@ public final class BitVector implements StrictLogicType, Iterable singleBitOperation) + { + Bit[] newBits = bits.clone(); + newBits[msbIndex] = singleBitOperation.apply(newBits[msbIndex]); + return new BitVector(newBits); + } + /** * Iterate over the {@link Bit}s of the BitVector from MSB to LSB (left to right). */ @@ -468,7 +487,7 @@ public final class BitVector implements StrictLogicType, Iterable