Skip to content

Instantly share code, notes, and snippets.

@davassi
Last active October 20, 2016 20:34
Show Gist options
  • Save davassi/808576e1100bedc2c2b2f929fa1f78a2 to your computer and use it in GitHub Desktop.
Save davassi/808576e1100bedc2c2b2f929fa1f78a2 to your computer and use it in GitHub Desktop.
binary truth table
private static final int not(int a) {
return a^0b1;
}
//https://s16.postimg.org/dthtvw3id/binary_curl.png
private static int rt(int a, int b, int c, int d) {
return ((a ^ d) & (not(b) | c));
}
private static int lt(int a, int b, int c, int d) {
return ((b ^ c) | (rt(a,b,c,d)));
}
public static int binaryTruth(int a, int b, int c, int d) {
int x1 = not(rt(a,b,c,d));
int x2 = lt(a,b,c,d);
if (x1 == 1 && x2 == 0) {
return -1;
}
if (x1 == 1 && x2 == 1) {
return 0;
}
return 1;
}
public static int invokeBinaryTruthOn(int x1, int x2) {
int a,b,c,d;
switch (x1) { // switch is direct O(1)
case 0: {a=1; b=1;} break;
case 1: {a=0; b=1;} break;
default: {a=1; b=0;}
}
switch (x2) {
case 0: {c=1; d=1;} break;
case 1: {c=0; d=1;} break;
default: {c=1; d=0;}
}
return IotaCurlUtils.binaryTruth(a,b,c,d);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment