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=63ff99fcb27b6248b62abb01275b9f36dc25544b;hp=e17ae6e1a233cbf7af23c3c68ac52cf37e002e13;hpb=91969fbb8e1a846c21cdfe6dc7e2b20534d86119;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 e17ae6e1..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 @@ -66,9 +66,7 @@ public final class BitVector implements StrictLogicType, Iterable, Iterableoffset to the right.
- * Therefore offset + other.length() <= this.length() needs to be true. + * Therefore offset + other.length() <= this.wdith() needs to be true. * * @throws ArrayIndexOutOfBoundsException if offset + other.length() > this.length() * @@ -421,12 +419,19 @@ public final class BitVector implements StrictLogicType, 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). */