X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Ftypes%2FBitVector.java;h=cce83f43330a9231ee8a37f1bbcf301784430fe0;hb=47ea68ed5c444dd14864412639f6a6fd60ab8a0f;hp=9e09f43a4f06c79c1c52f73dde132fd2c1f24f4f;hpb=4ac977cb31feb34f24e05e9d5e7976951dccf557;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 9e09f43a..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,7 @@ 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(); @@ -224,16 +234,38 @@ public final class BitVector implements StrictLogicType, IterablebitIndex. (leftmost bit of a binary number at the given index) + */ + public void setMSBit(int bitIndex, Bit bit) { bits[bitIndex] = bit; } - public Bit getBit(int bitIndex) + /** + * 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; @@ -286,45 +318,26 @@ public final class BitVector implements StrictLogicType, Iterable, Iterablefrom MSB to LSB (left to right). */ - public static BitVector parseMSBFirst(String s) - { - Bit[] values = new Bit[s.length()]; - for (int i = 0, j = s.length() - 1; j >= 0; i++, j--) - { - values[i] = Bit.parse(s, j); - } - return new BitVector(values); - } - @Override public Iterator iterator() { @@ -361,7 +362,7 @@ public final class BitVector implements StrictLogicType, Iterable