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=e8a40988c62c92ec89efda689875d593c878c7b6;hpb=faa90c5086c9be5550b6696cb47d976ccea66906;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 e8a40988..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 @@ -57,37 +57,17 @@ public final class BitVector implements StrictLogicType, Iterable, Iterable, Iterable + * An empty BitVectorMutator must not be converted to BitVector or used to manipulate single bits until at least one two + * operand logic operation is performed. */ public static BitVectorMutator empty() { return new BitVectorMutator(null); } + /** + * @see #empty() + */ + public boolean isEmpty() + { + return bits == null; + } + /** * Produces the resulting, immutable {@link BitVector}
* @@ -311,6 +307,8 @@ public final class BitVector implements StrictLogicType, Iterable, Iterable, Iterable, 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() * @@ -404,6 +410,33 @@ public final class BitVector implements StrictLogicType, Iterable= 0; i--) + { + if (Bit.ONE == bits[bits.length - i - 1]) + { + try + { + bytes[bytes.length - (i / 8) - 1] |= 1 << (i % 8); + } + catch (IndexOutOfBoundsException e) + { + e.printStackTrace(); + } + } + } + return new BigInteger(bytes); + } + /** * Parses a String containing solely {@link Bit} symbols (MSB first) * @@ -419,19 +452,18 @@ public final class BitVector implements StrictLogicType, Iterable singleBitOperation) { - Bit[] values = new Bit[bits]; - for (int i = 0; i < bits; i++) - { - values[bits - i - 1] = Bit.of(value.testBit(i)); - } - return new BitVector(values); + Bit[] newBits = bits.clone(); + newBits[msbIndex] = singleBitOperation.apply(newBits[msbIndex]); + return new BitVector(newBits); } /**