Calciro

2's Complement Calculator

Enter a decimal number (positive or negative) and a bit width to find its two's complement representation, shown as the equivalent unsigned decimal value.

Fill in the required fields to see your result.

Use this calculator on your website

Add this free 2's Complement Calculator to your blog, article, or business website. Copy the embed code and publish it in minutes.

Perfect for blogs, WordPress, Webflow, and business websites.

This is the unsigned decimal value whose binary representation is the two's complement encoding of your input, at the given bit width.

Need a calculator like this?

Calciro can build a custom calculator around your formulas, pricing rules, or lead-generation process.

How Two's Complement Works

Two's complement is the standard way computers represent negative integers in binary — it lets addition and subtraction use the same circuitry regardless of sign.

How to Calculate a Two's Complement Value

For a negative number: invert all bits of the positive binary representation, then add 1. For a positive number, the binary representation is unchanged (with a leading 0 bit).

Two's Complement Formula

  1. Write the positive number in binary (using the target bit width)
  2. Invert every bit (0↔1)
  3. Add 1 to the result

Why Use Two's Complement Instead of a Sign Bit?

Because two's complement allows the same binary addition circuit to correctly handle both positive and negative numbers without special-casing subtraction — a plain "sign bit" representation would require separate addition and subtraction logic.

Two's Complement Examples

−5 in 8-bit two's complement: Binary 5 = 00000101. Invert = 11111010. Add 1 = 11111011.

Common Two's Complement Mistakes

Forgetting to specify a bit width — the same value's binary representation differs by bit width (8-bit, 16-bit, 32-bit, etc.). Confusing one's complement (simple bit inversion, no +1 step) with two's complement (inversion plus 1) — they're different, related concepts. Misreading the sign of a two's complement value — the leftmost bit indicates sign, but the whole remaining pattern must be interpreted together, not just that single bit.

How to Use This Calculator

Enter any decimal integer (negative numbers are supported) and the bit width (commonly 8, 16, or 32 bits).

Formula & Methodology

For a value V and bit width n, the two's complement unsigned equivalent is V mod 2^n, computed so the result always falls between 0 and 2^n − 1. For positive numbers this equals the number itself; for negative numbers it wraps around to the equivalent large unsigned value.

Example: −5 in 8 bits

2^8 = 256. −5 mod 256 = 251 (binary 11111011) — the standard 8-bit two's complement representation of −5.

Only supports integer inputs. If your value doesn't fit within the given bit width (i.e. is outside the representable range), the result will wrap around, matching real two's complement overflow behavior — check that your bit width is large enough for your value.

Related Calculators

Related Guides

Frequently Asked Questions

What is two's complement?
Two's complement is the standard way computers represent negative integers in binary — it lets addition and subtraction use the same circuitry for both positive and negative numbers.
How do you calculate two's complement by hand?
Invert all the bits of the positive binary representation, then add 1. This calculator does the equivalent arithmetic directly using modular arithmetic.
What bit width should I use?
Use whatever width your system or assignment specifies — commonly 8 bits (bytes), 16 bits, or 32 bits.

Last updated 7/15/2026