Anyone happen to have a truth table sourc-code?
Author |
Message |
Fantasy #1 / 8
|
Anyone happen to have a truth table sourc-code?
I want to study how truth table works in C. -- - <-------------------FantasyZ----------------------->
ooO_(_)_Ooo_______________ __|_____|_____|_____|_____|__ _|_Born_|__to__|__be__|_Free__-|
|
Sat, 21 Dec 2002 03:00:00 GMT |
|
|
Ben Pfaf #2 / 8
|
Anyone happen to have a truth table sourc-code?
Quote:
> I want to study how truth table works in C.
Care to elaborate? I can think of several ways of implementing a truth right off the top of my head. -- "Give me a couple of years and a large research grant, and I'll give you a receipt." --Richard Heathfield
|
Sat, 21 Dec 2002 03:00:00 GMT |
|
|
vrml3d.co #3 / 8
|
Anyone happen to have a truth table sourc-code?
Quote: > I want to study how truth table works in C.
#include <stdio.h> #define PRINT_TRUTH(op,op_name) printf("OP: %s\n",op_name);\ printf("0 %s 0 = %i\n",op_name,0 op 0);\ printf("0 %s 1 = %i\n",op_name,0 op 1);\ printf("1 %s 0 = %i\n",op_name,1 op 0);\ printf("1 %s 1 = %i\n\n",op_name,1 op 1) int main() { PRINT_TRUTH(&&,"AND"); PRINT_TRUTH(||,"OR"); PRINT_TRUTH(^,"EOR"); return 0; Quote: }
|
Sun, 22 Dec 2002 03:00:00 GMT |
|
|
Regi #4 / 8
|
Anyone happen to have a truth table sourc-code?
Quote:
> > I want to study how truth table works in C. > #include <stdio.h> > #define PRINT_TRUTH(op,op_name) printf("OP: %s\n",op_name);\ > printf("0 %s 0 = %i\n",op_name,0 op 0);\ > printf("0 %s 1 = %i\n",op_name,0 op 1);\ > printf("1 %s 0 = %i\n",op_name,1 op 0);\ > printf("1 %s 1 = %i\n\n",op_name,1 op 1) > int main() > { > PRINT_TRUTH(&&,"AND"); > PRINT_TRUTH(||,"OR"); > PRINT_TRUTH(^,"EOR"); > return 0; > }
Bzzzzzzzzzzzzzz!!!!!!!!! int main (void) { int i= 0; if (i) PRINT_TRUTH(&&, "AND"); return 0; Quote: }
Rgis
|
Sun, 22 Dec 2002 03:00:00 GMT |
|
|
Regi #5 / 8
|
Anyone happen to have a truth table sourc-code?
Quote:
> > > I want to study how truth table works in C. > > #include <stdio.h> > > #define PRINT_TRUTH(op,op_name) printf("OP: %s\n",op_name);\ > > printf("0 %s 0 = %i\n",op_name,0 op 0);\ > > printf("0 %s 1 = %i\n",op_name,0 op 1);\ > > printf("1 %s 0 = %i\n",op_name,1 op 0);\ > > printf("1 %s 1 = %i\n\n",op_name,1 op 1)
Note that "^" is a bitwise operator whereas "&&" "||" are logical operators, so a truth table for "^" has 2 to the power of (CHAR_BIT*sizeof(an_integer_type)) entries and not only 4. Moreover, since non-zero means true we have 2 ^ 4 == binary(010) ^ binary(100) == binary (110) == 6 that is true ^ true == true whereas it would have yield false if the operator was logical. Question: in a one-complement machine is the result of (1 - 1) ^ 0 predictable ? Rgis
|
Sun, 22 Dec 2002 03:00:00 GMT |
|
|
Fantasy #6 / 8
|
Anyone happen to have a truth table sourc-code?
wow, surpise me with such responses erm, it is about entering a string containing the expression to be evaluated, e.g. A.B+C, from here is evaluate the answer whether is it 1 or 0. You see i don't know the mathematic formulate to be written in C <pss, yeah i know u guys can think right of your head... but...i can't ;o) -- - <-------------------FantasyZ----------------------->
ooO_(_)_Ooo_______________ __|_____|_____|_____|_____|__ _|_Born_|__to__|__be__|_Free__-|
Quote:
> > I want to study how truth table works in C. > Care to elaborate? I can think of several ways of implementing a > truth right off the top of my head. > -- > "Give me a couple of years and a large research grant, > and I'll give you a receipt." --Richard Heathfield
|
Sun, 22 Dec 2002 03:00:00 GMT |
|
|
Joona I Palast #7 / 8
|
Anyone happen to have a truth table sourc-code?
: wow, surpise me with such responses : erm, it is about entering a string containing the expression to be : evaluated, e.g. A.B+C, from here is evaluate the answer whether is it 1 or : 0. : You see i don't know the mathematic formulate to be written in C : <pss, yeah i know u guys can think right of your head... but...i can't ;o) ANSI C doesn't provide any functions to calculate the value of a mathematical expression supplied as a string. You have to write the calculation functions yourself. It's mostly trivial, you just have to put operands on one stack, operators on another, and when you're finished, you're left with one value in the operands stack, that's the result. I don't have the time or space to make a full document about the calculation functions here. --
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #80 D+ ADA N+++ | | http://www.helsinki.fi/~palaste W++ B OP+ | \----------------------------------------- Finland rules! ------------/ "You could take his life and..." - Mirja Tolsa
|
Sun, 22 Dec 2002 03:00:00 GMT |
|
|
Dik T. Winte #8 / 8
|
Anyone happen to have a truth table sourc-code?
> Question: > in a one-complement machine is the result of > (1 - 1) ^ 0 > predictable ? If you want to know whether the result is all bits set or all bits clear, no, that is not predictable across all ones-complement machines. I have worked with a machine were (1-1) would be -0 and with a machine were it would be +0. -- dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131 home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
|
Sun, 22 Dec 2002 03:00:00 GMT |
|
|
|