3 import java.util.Arrays;
9 public static Bit and(Bit a, Bit b)
14 public Bit and(Bit other)
16 if (this == ZERO || other == ZERO)
18 else if (this == other && this == ONE)
20 else if (this == X || other == X)
26 public static Bit or(Bit a, Bit b)
31 public Bit or(Bit other)
33 if (this == ONE || other == ONE)
35 else if (this == other && this == ZERO)
37 else if (this == X || other == X)
43 public static Bit xor(Bit a, Bit b)
48 public Bit xor(Bit other)
50 if(this == X || this == Z || other == X || other == Z)
53 return this == other ? ZERO : ONE;
69 public Bit[] makeArray(int length)
71 Bit[] bits = new Bit[length];
72 Arrays.fill(bits, this);
77 * Rules for two bits that get directly connected<br>
80 * <tr><td><td>X<td>0<td>1<td>Z</tr>
81 * <tr><td>X<td>X<td>X<td>X<td>X</tr>
82 * <tr><td>0<td>X<td>0<td>X<td>0</tr>
83 * <tr><td>1<td>X<td>X<td>1<td>1</tr>
84 * <tr><td>Z<td>X<td>0<td>1<td>Z</tr>
88 * @return the result according to the table
90 * @author Christian Femers
92 public Bit combineWith(Bit other)
96 if (this == X || other == X)
105 public static Bit combine(Bit a, Bit b)
107 return a.combineWith(b);