Created
January 2, 2009 17:50
-
-
Save d0k/42615 to your computer and use it in GitHub Desktop.
C program to generate LaTeX truth tables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ./wtab n | |
* creates a truth table for LaTeX with n bits | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define SIZE unsigned long | |
#define MAXBITS sizeof(SIZE)*8-1 | |
int main(int argc, char *argv[]) { | |
SIZE i; | |
int j, cols; | |
if (argc != 2 || (cols = atoi(argv[1])) <= 0 || cols > MAXBITS) { | |
fprintf(stderr, "wrong column count (max %d)\n", MAXBITS); | |
return EXIT_FAILURE; | |
} | |
for (i = 0; i < (1 << cols); i++) { | |
for(j = cols-1; j >= 0; j--) | |
printf("%d & ", ((i & (1 << j)) >> j)); | |
putchar('\n'); | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment