Intermediate

Two's Complement Calculator

Convert between signed decimal integers and their fixed-width two's-complement binary and hexadecimal forms.

Mode

Enter a signed decimal integer.

Bit width

Signed decimal
-42

Value interpreted from the bit pattern

Two’s-complement binary
1101 0110
Signed decimal
-42
Hexadecimal
0xD6
Bit width
8-bit
Set bits
5
Representable range
-128 .. 127
-128-96.1-64.3-32.4-0.531.463.395.1127Decimal value within the representable range
Results are estimates for general information only and are not professional advice — always verify important results independently before relying on them. Read the full disclaimer.
Quick answer

How does this calculator work?

A two's-complement calculator converts a signed decimal integer into its fixed-width binary and hexadecimal encoding, or decodes a bit pattern back to decimal. Non-negative values map directly; negatives are stored as v + 2^w. With w bits the range is −2^(w−1) to 2^(w−1) − 1, and the top bit gives the sign.

Formula
Encode: pattern = v (if v ≥ 0) or v + 2^w (if v < 0), kept to w bits. Decode: value = u − 2^w if MSB = 1, else u. Range = −2^(w−1) .. 2^(w−1) − 1
How this is calculated

Two's complement is the standard way computers store signed integers in a fixed number of bits (w). The Mode selector chooses the direction: Decimal → Binary takes a signed decimal value, while Binary → Decimal takes a raw bit pattern. The Value field accepts either a signed decimal integer or a string of 0s and 1s, and Bit width sets w to 8, 16, 32, or 64.

To encode a decimal v, non-negative values are written directly in binary and zero-padded to w bits. Negative values are encoded as v + 2^w, which is equivalent to inverting the bits of |v| − 1 (the invert-and-add-one rule); the result is truncated to w bits. To decode a w-bit unsigned reading u, the most significant bit is the sign: if it is 1 the true value is u − 2^w, otherwise the value is simply u. The hexadecimal output is the same unsigned bit pattern written in base 16.

A w-bit field represents integers from −2^(w−1) to 2^(w−1) − 1; the calculator rejects decimals outside this range and rejects bit patterns longer than w. Because 64-bit values exceed JavaScript's safe integer limit, the math is done with BigInt for exact binary and hexadecimal output, though the headline decimal card may round very large 64-bit magnitudes when displayed.

Frequently asked questions

In two's complement a negative value is stored as v + 2^w, so −1 in 8 bits becomes 0xFF and in 32 bits becomes 0xFFFFFFFF. The leading bits are 1s representing the sign, not a huge positive magnitude.

With w bits the representable signed range is −2^(w−1) to 2^(w−1) − 1. For 8 bits that is −128 to 127, and for 16 bits it is −32768 to 32767. Values outside this range cannot be encoded.

Look at the most significant (leftmost) bit. If it is 1 the number is negative and equals u − 2^w; if it is 0 the number is non-negative and equals u directly.

Also known as

twos complement calculator
signed binary
two's complement converter
negative binary
signed integer encoding
two's complement

APA

TG we-Calculate Editorial Team. (2026). Two's Complement Calculator [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/twos-complement-calculator

Chicago

TG we-Calculate Editorial Team. "Two's Complement Calculator." TG we-Calculate. 2026. https://we-calculate.com/calculator/twos-complement-calculator.

IEEE

TG we-Calculate Editorial Team, "Two's Complement Calculator," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/twos-complement-calculator

BibTeX

@misc{wecalculate_twos_complement_calculator, title = {Two's Complement Calculator}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/twos-complement-calculator}}, year = {2026}, note = {TG we-Calculate} }

Did this calculator help you?