Skip to content

Instantly share code, notes, and snippets.

@wpcarro
Created May 22, 2024 17:39
Show Gist options
  • Save wpcarro/a72f97cffe13f49ca541e46b02b46c93 to your computer and use it in GitHub Desktop.
Save wpcarro/a72f97cffe13f49ca541e46b02b46c93 to your computer and use it in GitHub Desktop.
Logic gates from NOT, OR
// NOT: given
// OR: given
// NOR: derived
// AND: derived
// NAND: derived
// XOR: derived
// XNOR: derived
function nor(x: boolean, y: boolean): boolean {
return !(x || y);
}
function and(x: boolean, y: boolean): boolean {
return !(!x || !y);
}
function nand(x: boolean, y: boolean): boolean {
return !and(x, y);
}
function xor(x: boolean, y: boolean): boolean {
return and(!x, y) || and(x, !y);
}
function xnor(x: boolean, y: boolean): boolean {
return !xor(x, y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment