X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Ftypes%2FBitVector.java;h=cce83f43330a9231ee8a37f1bbcf301784430fe0;hb=e8e95e2e345f4d9c5927aa78f5c0fb607d352a97;hp=1e87f9a43cba1c5ec9c4d181571843987b0d599b;hpb=07faf07e3acb8b2afdc2bf65a46bc868faaed0f8;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 1e87f9a4..cce83f43 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 @@ -13,7 +13,6 @@ import java.util.function.UnaryOperator; /** * Immutable class representing a {@link Bit}Vector * - * * @author Christian Femers * */ @@ -23,7 +22,10 @@ public final class BitVector implements StrictLogicType, Iterable, IterablebitIndex. (leftmost bit of a binary number at the given index) + */ + public Bit getMSBit(int bitIndex) { return bits[bitIndex]; } + /** + * Returns the least significant bit at bitIndex. (rightmost bit of a binary number at the given index) + */ + public Bit getLSBit(int bitIndex) + { + return bits[bits.length - bitIndex - 1]; + } + public Bit[] getBits() { return bits.clone(); @@ -140,7 +153,6 @@ public final class BitVector implements StrictLogicType, Iterable { private Bit[] bits; @@ -155,9 +167,16 @@ public final class BitVector implements StrictLogicType, Iterablewith all bits set to null. Use with care! + */ + public static BitVectorMutator ofLength(int length) + { + return new BitVectorMutator(new Bit[length]); + } + /** * Returns an empty mutator which has no bits set and will simply copy the values from the first binary operation performed. - * */ public static BitVectorMutator empty() { @@ -169,7 +188,7 @@ public final class BitVector implements StrictLogicType, Iterable, IterablebitIndex. (leftmost bit of a binary number at the given index) + */ + public void setMSBit(int bitIndex, Bit bit) + { + bits[bitIndex] = bit; + } + + /** + * Set the least significant bit at bitIndex. (rightmost bit of a binary number at the given index) + */ + public void setLSBit(int bitIndex, Bit bit) + { + bits[bits.length - bitIndex - 1] = bit; + } + + /** + * Returns the most significant bit at bitIndex. (leftmost bit of a binary number at the given index) + */ + public Bit getMSBit(int bitIndex) + { + return bits[bitIndex]; + } + + /** + * Returns the least significant bit at bitIndex. (rightmost bit of a binary number at the given index) + */ + public Bit getLSBit(int bitIndex) + { + return bits[bits.length - bitIndex - 1]; + } + + public int length() + { + return bits.length; + } + private void checkCompatibility(BitVector bv) { if (bits != null && bits.length != bv.length()) @@ -263,7 +319,7 @@ public final class BitVector implements StrictLogicType, Iterable, Iterable, Iterablefrom MSB to LSB (left to right). + */ @Override public Iterator iterator() { @@ -303,7 +362,7 @@ public final class BitVector implements StrictLogicType, Iterable