X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Ftypes%2FBit.java;h=752fbb80e774fcb124c0d925c1403485fa6f8311;hb=8bed58cd47f4e53a0a83e066d38864aa6875502f;hp=707c5ad4bc2bd2bcd0b5619451cdd3be4e0a9bf6;hpb=b37ba7609a925cc945bbac0f6ead619d07912238;p=Mograsim.git diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/types/Bit.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/types/Bit.java index 707c5ad4..752fbb80 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/types/Bit.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/types/Bit.java @@ -18,24 +18,52 @@ public enum Bit implements StrictLogicType this.symbol = symbol; } + /** + * Returns if the Bit is binary, this is only true for ZERO and ONE. + * + * @return true if and only if this == ONE || this == ZERO + */ + public boolean isBinary() + { + return this == ONE || this == ZERO; + } + @Override public Bit and(Bit other) { return fromTable(AND_TABLE, this, other); } + public static void and(Bit[] dst, Bit[] src) + { + for (int i = 0; i < dst.length; i++) + dst[i] = dst[i].and(src[i]); + } + @Override public Bit or(Bit other) { return fromTable(OR_TABLE, this, other); } + public static void or(Bit[] dst, Bit[] src) + { + for (int i = 0; i < dst.length; i++) + dst[i] = dst[i].or(src[i]); + } + @Override public Bit xor(Bit other) { return fromTable(XOR_TABLE, this, other); } + public static void xor(Bit[] dst, Bit[] src) + { + for (int i = 0; i < dst.length; i++) + dst[i] = dst[i].xor(src[i]); + } + @Override public Bit not() { @@ -59,6 +87,11 @@ public enum Bit implements StrictLogicType return bits; } + public BitVector toVector() + { + return BitVector.of(this, 1); + } + public BitVector toVector(int length) { return BitVector.of(this, length); @@ -70,6 +103,12 @@ public enum Bit implements StrictLogicType return fromTable(JOIN_TABLE, this, other); } + public static void join(Bit[] dst, Bit[] src) + { + for (int i = 0; i < dst.length; i++) + dst[i] = dst[i].join(src[i]); + } + @Override public String toString() { @@ -86,6 +125,11 @@ public enum Bit implements StrictLogicType return values()[2 + (value & 1)]; } + public static Bit of(boolean binaryValue) + { + return binaryValue ? ONE : ZERO; + } + public static Bit parse(String s) { Bit bit = SYMBOL_MAP.get(s);