# Two's complement visualised: signed integer for hardware and C

> Interactive n-bit two's complement: negation by flipping all bits plus one, unique zero, asymmetric value range. Standard for int8 to int32.

Address: https://marckimmel.de/en/informatik/zahlenkodierungen/zweierkomplement
Deutsche Fassung: https://marckimmel.de/informatik/zahlenkodierungen/zweierkomplement.md

Today's standard for signed integers: negation by bitflip plus one, single zero.

Two's complement c_(2K,n) is the de facto standard for signed types in modern CPUs. Zero has exactly one code (0...0), and patterns starting with 1 are always negative. Range: -2^(n-1) to 2^(n-1)-1 (asymmetric: one more negative than positive). Negation by bitflip + 1. Addition runs as plain binary addition; on bit overflow the top bit is discarded (modulo 2^n).

In C used by the signed types: signed char, short, int, long, long long. Practically all x86, ARM and RISC-V processors use two's complement.

## Related

- [Number Encodings](https://marckimmel.de/en/informatik/zahlenkodierungen.md)
