boolcalc is a simple RPN (reverse polish notation) boolean calculator. It allows the four main boolean operators: AND, OR, XOR, and NOT, as well as very simple support for D-latches and JK flip-flops. After reading the expression, it prints out a truth table for it.
This program is placed in the public domain. It uses pretty standard techniques, so I did not feel the necessity to put any licence on it. Feel free to modify the program in any way you see fit. Copy it, redistribute it, and use it in any way you want -- I don't care, as long as it's all honest and legal. (Of course, it's always nice to acknowledge your sources ;-) )
boolcalc takes no command line arguments. It reads from stdin and writes to stdout, so you can easily type expressions into text files, redirect the input to the file, and then redirect the output to another file.
The input has the following format:
Input | Meaning |
---|---|
1, 0 | Boolean constants. |
A, B, C, ..., H | The input gates. Valid gates start from A. eg. if you have two inputs, they will be A and B |
&, * | AND (pop two things off the stack, and connect them with an AND gate) |
|, + | OR |
^ | XOR |
! | NOT |
d | D-latch (pop two things off the stack: the first (ie. last one pushed onto the stack) is the D-input, the second (ie. first one pushed onto the stack) is the previous state. |
j | JK flip-flop (pop three things off the stack: K, J, and the previous state.) |
'\n', <eof> | Marks the end of the expression |
For example, the following input: "3 A B + C * '\n' A C! + B! ^ '\n'" would result in the functions f1=(A+B)*C and f2=(A+(!C))^(!B).
The expressions must be in RPN notation. That is, the operands come first, and then the operator. eg. ABC+* -> A*(B+C) To check that you got it right, boolcalc will print out the expression in `normal' format. Note that, as far as boolcalc is concerned, + has higher precedence than ^ so if it prints out A^B+C, it means A^(B+C).
After it prints out the expression, it prints out a truth table. On the left side are the inputs, and on the right side are the results of the espressions. This should be fairly self-explanatory.
No, there aren't really any bugs, at least that I'm aware of. Just some shortcuts that I made that might cause some problems if you're not aware of them. I assume that you're all intelligent people, and so you can properly formulate an RPN expression with the proper number of gates, so there shouldn't be any problems. But just in case you mess something up and you want to know what's wrong...
My home page (the one that you'll be able to find boolcalc) is
here.
[ Back ]
Last updated November 9, 1997. <><