Search in sources :

Example 1 with ThreeStateValue

use of de.neemann.digital.analyse.quinemc.ThreeStateValue in project Digital by hneemann.

the class TruthTableFormatterLaTeX method format.

@Override
public String format(TruthTable truthTable) throws ExpressionException {
    StringBuilder sb = new StringBuilder();
    sb.append("\\begin{center}\n\\begin{tabular}{");
    for (Variable v : truthTable.getVars()) sb.append("c");
    sb.append("|");
    for (int i = 0; i < truthTable.getResultCount(); i++) sb.append("c");
    sb.append("}\n");
    for (Variable v : truthTable.getVars()) sb.append("$").append(formatVar(v.getIdentifier())).append("$&");
    for (int i = 0; i < truthTable.getResultCount(); i++) {
        sb.append("$").append(formatVar(truthTable.getResultName(i))).append("$");
        if (i < truthTable.getResultCount() - 1)
            sb.append("&");
    }
    sb.append("\\\\\n");
    sb.append("\\hline\n");
    ContextFiller cf = new ContextFiller(truthTable.getVars());
    for (int i = 0; i < cf.getRowCount(); i++) {
        cf.setContextTo(i);
        for (Variable v : cf) sb.append(format(cf.get(v))).append("&");
        for (int j = 0; j < truthTable.getResultCount(); j++) {
            ThreeStateValue r = truthTable.getResult(j).get(i);
            sb.append(format(r));
            if (j < truthTable.getResultCount() - 1)
                sb.append("&");
        }
        sb.append("\\\\\n");
    }
    sb.append("\\end{tabular}\n\\end{center}\n");
    return sb.toString();
}
Also used : ThreeStateValue(de.neemann.digital.analyse.quinemc.ThreeStateValue) Variable(de.neemann.digital.analyse.expression.Variable) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller)

Example 2 with ThreeStateValue

use of de.neemann.digital.analyse.quinemc.ThreeStateValue in project Digital by hneemann.

the class TruthTable method saveHex.

/**
 * Save the table as hex file to be loaded in a ROM or LUT element.
 *
 * @param writer the filename to use
 * @throws IOException IOException
 */
public void saveHex(Writer writer) throws IOException {
    writer.write("v2.0 raw\n");
    int count = results.get(0).getValues().size();
    for (int i = 0; i < count; i++) {
        long val = 0;
        long mask = 1;
        for (Result r : results) {
            ThreeStateValue v = r.getValues().get(i);
            if (v == ThreeStateValue.one)
                val |= mask;
            mask *= 2;
        }
        writer.write(Long.toHexString(val));
        writer.write('\n');
    }
}
Also used : ThreeStateValue(de.neemann.digital.analyse.quinemc.ThreeStateValue)

Aggregations

ThreeStateValue (de.neemann.digital.analyse.quinemc.ThreeStateValue)2 ContextFiller (de.neemann.digital.analyse.expression.ContextFiller)1 Variable (de.neemann.digital.analyse.expression.Variable)1