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=8bff357a1cf02cd41e75b0b8f440765f0255e1b1;hpb=47ea68ed5c444dd14864412639f6a6fd60ab8a0f;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 8bff357a..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,6 +18,11 @@ 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; @@ -29,18 +34,36 @@ public enum Bit implements StrictLogicType 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() { @@ -64,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); @@ -75,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() {