3 import java.util.Arrays;
9 public static Bit and(Bit a, Bit b)
14 public Bit and(Bit other)
16 if (equals(Bit.ZERO) || other.equals(Bit.ZERO))
18 else if (equals(other) && equals(Bit.ONE))
24 public static Bit or(Bit a, Bit b)
29 public Bit or(Bit other)
31 if (equals(Bit.ONE) || other.equals(Bit.ONE))
33 else if (equals(other) && equals(Bit.ZERO))
39 public static Bit xor(Bit a, Bit b)
44 public Bit xor(Bit other)
46 if(this == Bit.X || this == Bit.Z
47 || other == Bit.X || other == Bit.Z)
50 return this == other ? Bit.ZERO : Bit.ONE;
66 public Bit[] makeArray(int length)
68 Bit[] bits = new Bit[length];
69 Arrays.fill(bits, this);
74 * Rules for two bits that get directly connected<br>
77 * <tr><td><td>X<td>0<td>1<td>Z</tr>
78 * <tr><td>X<td>X<td>X<td>X<td>X</tr>
79 * <tr><td>0<td>X<td>0<td>X<td>0</tr>
80 * <tr><td>1<td>X<td>X<td>1<td>1</tr>
81 * <tr><td>Z<td>X<td>0<td>1<td>Z</tr>
85 * @return the result according to the table
87 * @author Christian Femers
89 public Bit combineWith(Bit other)
93 if (this == X || other == X)
102 public static Bit combine(Bit a, Bit b)
104 return a.combineWith(b);