X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Ftypes%2FBit.java;h=119ee53ae308d6faafb035d9175ff0f450ac30b0;hb=0ab3dafe756a69ff8b1e0137058caf2f5ac564aa;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..119ee53a 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() { @@ -70,6 +98,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 +120,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);