2 complement calculator

Interactive 2's Complement Calculator

Convert decimal numbers to two's complement binary, or convert binary two's complement values back to decimal.

For decimal input, bit width sets the valid numeric range.
Accepted format: integer only (e.g., -15, 0, 127).
Ready. Choose a mode, enter a value, and click Calculate.

What is 2's complement?

Two's complement (often written as 2's complement) is the most common way computers represent signed integers. Instead of storing a separate sign bit and magnitude, two's complement uses one binary pattern format for both positive and negative values. This makes arithmetic simpler and faster for hardware.

In an n-bit system, the representable range is:

  • Minimum: -2^(n-1)
  • Maximum: 2^(n-1) - 1

For example, with 8 bits, the signed range is -128 to 127.

How to use this calculator

1) Decimal to two's complement

  • Select Decimal → 2's Complement Binary.
  • Choose a bit width (8, 16, 32, etc.).
  • Enter an integer, like -18 or 75.
  • Click Calculate to get binary and hexadecimal output.

2) Two's complement binary to decimal

  • Select 2's Complement Binary → Decimal.
  • Enter a binary value like 11101110.
  • Pick a width, or choose Auto to use the input length.
  • Click Calculate to get signed and unsigned decimal values.

Manual example: convert -18 to 8-bit two's complement

  1. Start with +18 in binary: 00010010
  2. Invert bits: 11101101
  3. Add 1: 11101110

So, -18 in 8-bit two's complement is 11101110. If you run that pattern back through the calculator in reverse mode, you'll get signed decimal -18.

Why this matters in programming and digital systems

Understanding two's complement helps with low-level debugging, embedded systems, networking, compilers, and even cryptographic or performance-sensitive software. It's especially useful when you inspect raw bytes, bit masks, overflow behavior, and integer casts between signed and unsigned types.

  • Interpreting memory dumps and packet data
  • Handling overflow in fixed-width integer arithmetic
  • Working with C/C++, Rust, Java, and assembly-level data models
  • Converting between binary, decimal, and hexadecimal cleanly

Common mistakes to avoid

  • Ignoring bit width: 11111111 means -1 in 8-bit signed, but 255 unsigned.
  • Using out-of-range decimal inputs: each bit width has strict min/max limits.
  • Dropping leading bits carelessly: truncation can completely change sign and value.
  • Mixing signed/unsigned interpretation: same bits, different numeric meaning.

Quick reference ranges

  • 4-bit: -8 to 7
  • 8-bit: -128 to 127
  • 16-bit: -32,768 to 32,767
  • 32-bit: -2,147,483,648 to 2,147,483,647

Use the calculator above any time you need fast, accurate two's complement conversions.

🔗 Related Calculators