3 import java.util.Arrays;
6 * stdlogic according to IEEE 1164
12 public static Bit and(Bit a, Bit b)
17 public Bit and(Bit other)
19 return fromTable(AND_TABLE, this, other);
22 public static Bit or(Bit a, Bit b)
27 public Bit or(Bit other)
29 return fromTable(OR_TABLE, this, other);
32 public static Bit xor(Bit a, Bit b)
37 public Bit xor(Bit other)
39 return fromTable(XOR_TABLE, this, other);
57 public Bit[] makeArray(int length)
59 Bit[] bits = new Bit[length];
60 Arrays.fill(bits, this);
64 public Bit combineWith(Bit other)
66 return fromTable(JOIN_TABLE, this, other);
69 public static Bit combine(Bit a, Bit b)
71 return a.combineWith(b);
74 private static Bit fromTable(Bit[][] table, Bit a, Bit b)
76 return table[a.ordinal()][b.ordinal()];
80 private static Bit[][] JOIN_TABLE =
83 { U, X, ZERO, X, ZERO },
84 { U, X, X, ONE, ONE },
85 { U, X, ZERO, ONE, Z } };
87 private static Bit[][] AND_TABLE =
88 { { U, U, ZERO, U, U },
90 { ZERO, ZERO, ZERO, ZERO, ZERO },
91 { U, X, ZERO, ONE, X },
92 { U, X, ZERO, X, X } };
94 private static Bit[][] OR_TABLE =
95 { { U, U, U, ONE, U },
97 { U, X, ZERO, ONE, X },
98 { ONE, ONE, ONE, ONE, ONE },
99 { U, X, X, ONE, X } };
101 private static Bit[][] XOR_TABLE =
104 { U, X, ZERO, ONE, X },
105 { U, X, ONE, ZERO, X },