Report

Help us improve this tool

One's Complement Calculator

Convert numbers between decimal and binary one's complement, invert bits, and perform signed binary arithmetic.

O M T

What Is One's Complement?

The one's complement of a binary number is formed by flipping (inverting) each bit: changing every 0 to 1 and every 1 to 0. In digital computing and signed arithmetic systems, one's complement provides a mathematical method for representing negative numbers and implementing subtraction using simple bitwise inversion and binary addition circuits.

In an $N$-bit signed one's complement system, the most significant bit (MSB) acts as the sign bit:

  • 0 in the MSB indicates a positive value.
  • 1 in the MSB indicates a negative value.

How to Calculate One's Complement

Depending on whether you start from a decimal integer or an existing binary pattern, follow these steps:

1. Converting Positive Decimal to One's Complement

  1. Convert the positive decimal value to standard binary using your chosen bit width (such as 8-bit).
  2. Ensure the MSB is 0.
  3. In signed notation, the positive number is left unchanged: for instance, $+7$ in 8-bit is 0000 0111.

2. Converting Negative Decimal to One's Complement

  1. Take the absolute magnitude of the number in binary (e.g. $|-7| = 7 \implies 0000\ 0111$).
  2. Invert every bit ($0 \to 1, 1 \to 0$).
  3. The resulting string 1111 1000 represents $-7$ in 8-bit one's complement.

3. Bitwise NOT Operation

In Boolean algebra and computer programming, the bitwise NOT operator (~) performs a pure bitwise one's complement inversion on every bit position.

One's Complement vs. Two's Complement

While modern processors primarily utilize two's complement for integer mathematics, one's complement remains widely used in networking protocols (such as IP and TCP/UDP checksum algorithms).

Property One's Complement Two's Complement
Inversion Rule Flip all bits ($0 \leftrightarrow 1$) Flip all bits then add 1
Representation of Zero Two zeros ($+0$: 0000 0000, $-0$: 1111 1111) Single zero (0000 0000)
8-Bit Range $-127$ to $+127$ ($[-2^{N-1}+1, 2^{N-1}-1]$) $-128$ to $+127$ ($[-2^{N-1}, 2^{N-1}-1]$)
Addition Handling Requires end-around carry Standard binary addition with discarded overflow

One's Complement Addition and End-Around Carry

When adding two numbers in one's complement, an overflow bit from the most significant column is called an end-around carry. To obtain the correct result, this carry bit must be cycled back and added to the least significant bit (LSB):

$$\text{Step 1: Compute raw sum } A + B$$

$$\text{Step 2: If carry-out } = 1, \text{ Add 1 to LSB}$$

Frequently Asked Questions

What is the one's complement of 7?

In 8-bit binary, positive 7 is written as 0000 0111. Inverting every bit gives 1111 1000, which represents $-7$ in signed 8-bit one's complement representation.

Why does one's complement have two zeros?

Because one's complement simply inverts all bits to represent negative numbers, inverting positive zero (0000 0000) produces negative zero (1111 1111). While both mathematically equal zero, this dual representation is one reason modern hardware prefer two's complement.

Where is one's complement used today?

One's complement arithmetic is the foundation of network checksums, such as the IPv4 header checksum and TCP/UDP checksum algorithms (RFC 791 and RFC 793). Because end-around carry addition is associative and endianness-independent, checksum verification is very fast to compute in hardware and software.

How do you convert one's complement back to decimal?

Inspect the leading bit (MSB). If the MSB is 0, convert the binary string directly to positive decimal. If the MSB is 1, the number is negative: flip all bits back to find the magnitude in binary, convert that to decimal, and attach a negative sign.

What is the formula for one's complement of a decimal number?

For an $N$-bit number $X$, the one's complement representation of $-X$ is mathematically equal to $(2^N - 1) - X$. For example, with $N = 8$ bits and $X = 7$, $(255 - 7) = 248$, which is 1111 1000 in binary.