/tuːz ˈkɒmplɪˌmɛnt/
noun … “the standard method for representing signed integers in binary.”
Two's Complement is a numeric encoding system used in digital computing to represent both positive and negative integers efficiently. In this scheme, a fixed number of bits (commonly 8, 16, 32, or 64) is used, where the most significant bit (MSB) serves as the sign bit: 0 indicates a positive number and 1 indicates a negative number. Unlike other signed integer representations, Two's Complement allows arithmetic operations such as addition, subtraction, and multiplication to work uniformly without special handling for negative values, simplifying hardware design in CPUs and arithmetic logic units.
To represent a negative number in Two's Complement, you invert all bits of its positive counterpart (forming the one's complement) and then add 1 to the least significant bit. For example, in INT8 format, -5 is represented as 11111011 because the positive 5 is 00000101, inverted to 11111010, and incremented by 1 to produce 11111011. This system naturally handles overflow modulo 2⁸ for 8-bit integers, ensuring arithmetic wraps around predictably.
Two's Complement is closely related to other integer types such as INT8, INT16, INT32, INT64, and UINT32. It is the preferred representation for signed integers in most modern architectures, including x86, ARM, and RISC-V, because it eliminates the need for separate subtraction logic and simplifies the comparison of signed values at the hardware level.
In practical workflows, Two's Complement enables efficient computation for algorithms involving both positive and negative numbers. It is used in arithmetic operations, digital signal processing, image processing, cryptography, and any low-level numerical computation requiring deterministic binary behavior. High-level languages such as Julia, C, Python, and Java abstract these details but rely on Two's Complement internally to represent signed integer types like INT8 and INT32.
An example of Two's Complement in practice with an INT8 integer:
let x: Int8 = -12
let y: Int8 = 20
let z = x + y # hardware uses Two's Complement to compute result
println(z) # outputs 8The intuition anchor is that Two's Complement acts as a mirror system: negative numbers are encoded as the “wrap-around” of their positive counterparts, allowing arithmetic to flow naturally in binary without extra logic. It is the hidden backbone behind signed integer operations, making computers handle both positive and negative values seamlessly.