Overview

One's complement is a basic binary operation that inverts every binary digit: each 0 becomes 1 and each 1 becomes 0. It is often described as the bitwise complement or logical NOT of a binary value. In low-level computing and digital logic this operation is distinct from arithmetic negation, although some early number representations used one's complement to encode negative values. For general background on binary notation see binary numbers.

Representation and simple examples

Applied to a fixed-width field, one's complement produces a new pattern with all the bits flipped. For example, in a 4-bit system the one's complement of 0101 is 1010. A notable consequence is that zero can have two representations: all zeros (0000) and all ones (1111) both evaluate to the additive identity when interpreted under ones' complement rules.

Arithmetic properties

When one's complement is used for signed integers, negative values are formed by taking the complement of the corresponding positive magnitude. Addition requires special handling: if an addition produces a carry out of the most significant bit, that carry must be added back into the least significant bit (an "end-around carry"). This extra step distinguishes one's complement arithmetic from two's complement arithmetic and from unsigned binary addition.

Uses and history

One's complement appeared in several early computer architectures as a convenient way to obtain a negative representation without separate sign bits. It also appears in certain checksum and error-detection schemes, where a one's-complement sum is used to fold multiword data into a compact checksum value. Over time, many systems migrated to two's complement because it simplifies hardware and eliminates the dual-zero problem.

Comparison and notable facts

Compared with sign-magnitude and two's complement representations, one's complement is simple to compute but introduces complications: two zeros and the need for end-around carry in addition. Two's complement removes both of these issues by defining negatives as the complement plus one; see two's complement for details. In modern programming, the bitwise complement operator (often written ~) performs the same basic inversion on binary representations, independent of whether the system uses one's- or two's-complement integer arithmetic.