Last active
June 7, 2022 22:24
-
-
Save rednafi/d8da3f48ba0d7e9afb13498e868bccba to your computer and use it in GitHub Desktop.
A simple two bit flip flop adder in TypeScript
This file contains 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
type Bit = 0 | 1; | |
type Zero = Extract<Bit, 0>; | |
type One = Exclude<Bit, Zero>; | |
type Flip<T extends Bit> = T extends Zero ? One : Zero; | |
type Add<T extends Bit, U extends Bit> = T extends Zero | |
? U extends Zero | |
? Zero | |
: One | |
: One; | |
type NotAdd<T extends Bit, U extends Bit> = Flip<Add<T, U>>; | |
type Result = NotAdd<One, Zero>; // 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment