Twos Complement
Enter a signed or unsigned integer and width. The result is the exact fixed-width value of (~x + 1) modulo 2^N, calculated with BigInt.
A QUICK WALKTHROUGH
How to use this tool
- Choose signed or unsigned input interpretation.
- Enter an integer and a width from 1 to 10,000 bits.
- Calculate the fixed-width two’s-complement bit pattern and its signed and unsigned values.
Explicit signed and unsigned ranges
Signed input must be between −2^(N−1) and 2^(N−1)−1. Unsigned input must be between 0 and 2^N−1. The selected width is always the exact output width.
Exact BigInt arithmetic
The calculation uses arbitrary-precision integers and computes (~x + 1) modulo 2^N, so large values and the signed minimum value are handled without floating-point rounding.
Local calculation
Validation and calculation run locally in your browser. No input is uploaded or stored.
GOOD TO KNOW
Common questions
What happens for the signed minimum value?
For −2^(N−1), two’s complement is the bit pattern 100…0. It is valid and remains the signed minimum when interpreted at the same width.
Can unsigned input be negative?
No. Unsigned input accepts only a non-negative decimal integer within 0 through 2^N−1.
Are there practical input limits?
The width is limited to 1–10,000 bits and the decimal input to 4,096 digits so the browser remains responsive.