X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Ftypes%2FBit.java;h=da7b8c910a7cda3b3393e7ae0e7a2917ff706165;hb=bd4c631689be1cc990848ce503a353947290a819;hp=fbfd0d567bdf8960da4fdc94abebdd63eda94043;hpb=07faf07e3acb8b2afdc2bf65a46bc868faaed0f8;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 fbfd0d56..da7b8c91 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,16 @@ 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) { @@ -81,6 +91,16 @@ public enum Bit implements StrictLogicType return symbol; } + public static Bit lastBitOf(int value) + { + 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);