2's Complement Generator

Design a circuit that outputs the two's complement of a 4-bit input: invert every bit and add 1, which negates the value modulo 16 (0101 becomes 1011, 0000 stays 0000, 1000 stays 1000).

Input: in, a 4-bit value.
Output: out, its 4-bit two's complement.

The testbench applies all 16 inputs and compares out with -in.

Contributed by Indicore

Compiler Output
Waveform Viewer