X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Ftypes%2FBit.java;h=e6278104bffa03b4b6ab42804aa53eeb0e4585d5;hb=f37f1f93f2c1ceb780f1c7ecab888bcb8f4f8b89;hp=707c5ad4bc2bd2bcd0b5619451cdd3be4e0a9bf6;hpb=f14ea37d69488dd51518a36413af7176916b8bd7;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..e6278104 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) { @@ -59,9 +69,9 @@ public enum Bit implements StrictLogicType return bits; } - public BitVector toVector(int length) + public BitVector toVector(int width) { - return BitVector.of(this, length); + return BitVector.of(this, width); } @Override @@ -86,6 +96,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);