Skip to content

Instantly share code, notes, and snippets.

@Siarkowy
Last active August 29, 2015 13:57
Show Gist options
  • Save Siarkowy/9565734 to your computer and use it in GitHub Desktop.
Save Siarkowy/9565734 to your computer and use it in GitHub Desktop.
ToLC Ex. 1 Section 2
#include <stdio.h>
// double complement !! for 0 or 1 only
#define x3 (!!(x & 0b1000))
#define x2 (!!(x & 0b0100))
#define x1 (!!(x & 0b0010))
#define x0 (!!(x & 0b0001))
// SOP
#define z3 (x3 && x2 || x3 && x1 && x0)
#define z2 (x3 || x2 && x1 && x0)
#define z1 (!x2 && !x1 && !x0 || x2 && x0 || x2 && x1)
#define z0 (!x1)
// NAND only
#define a3 (!(!(x3 && x2) && !(x3 && x1 && x0)))
#define a2 (!(!x3 && !(x2 && x1 && x0)))
#define a1 (!(!(!x2 && !x1 && !x0) && !(x2 && x0) && !(x2 && x1)))
#define a0 (!x1)
int main(void) {
int x;
for (x = 3; x < 13; ++x)
printf("%d\tdec %d\tEx3 %d%d%d%d\tGray %d%d%d%d\tNAND %d%d%d%d\n", x-3, x,
x3, x2, x1, x0,
z3, z2, z1, z0,
a3, a2, a1, a0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment