User Rating 0.0 ★★★★★
Total Usage 0 times
Quick presets:
Is this tool helpful?

Your feedback helps us improve.

★ ★ ★ ★ ★

About

Two's complement is the standard encoding for signed integers in virtually every modern CPU architecture. A single misinterpreted sign bit propagates through arithmetic pipelines and corrupts downstream results - buffer overflows, incorrect sensor readings, and financial miscalculations all trace back to this error class. This tool converts between decimal integers and their two's complement binary representation across 4, 8, 16, 32, and 64-bit widths. It validates that your value falls within the representable range [−2n−1, 2n−1 − 1] and generates a step-by-step breakdown of the conversion process.

The converter handles both directions: decimal to two's complement and two's complement back to decimal. It assumes standard binary positional notation with the most significant bit (MSB) serving as the sign bit. Limitation: this tool operates on fixed-width integers only. Floating-point representations (IEEE 754) require a different encoding scheme not covered here. Pro Tip: when debugging embedded firmware, always verify your compiler's assumed word width matches your target - a 16-bit int on an AVR is not the same as a 32-bit int on ARM Cortex.

twos complement binary converter decimal to binary signed binary two's complement calculator bit converter binary arithmetic

Formulas

Two's complement encoding for an n-bit signed integer maps a decimal value d to a binary string B of exactly n bits. The representable range is constrained to:

−2n − 1 ≤ d ≤ 2n − 1 − 1

For non-negative values (d â‰Ĩ 0), the binary representation is the standard positional expansion zero-padded to n bits:

B = pad(d2, n)

For negative values (d < 0), the encoding applies three steps:

Babs = pad(|d|2, n)
Binv = ÂŦBabs (invert every bit)
B = Binv + 1 (binary addition with carry)

The reverse conversion (binary to decimal) inspects the MSB (bit n − 1):

{
d = B10 if MSB = 0d = −(ÂŦB + 1)10 if MSB = 1

The weighted sum formula expresses the decimal value directly from bit positions:

d = −bn−1 ⋅ 2n−1 + n−2∑i=0 bi ⋅ 2i

Where bi is the bit at position i (0 or 1), n is the total bit width, and bn−1 is the sign bit carrying negative weight.

Reference Data

Bit WidthMin ValueMax ValueUnsigned MaxTotal ValuesCommon Use
4-bit−871516Nibble, BCD digits
8-bit−128127255256int8_t, Java byte
16-bit−32,76832,76765,53565,536int16_t, short
32-bit−2,147,483,6482,147,483,6474,294,967,2954,294,967,296int32_t, C int
64-bit−9,223,372,036,854,775,8089,223,372,036,854,775,80718,446,744,073,709,551,61518,446,744,073,709,551,616int64_t, long long
Common Two's Complement Values (8-bit)
DecimalBinaryHexNotes
00000 00000x00Zero
10000 00010x01Smallest positive
1270111 11110x7FLargest positive (8-bit)
−11111 11110xFFAll bits set
−21111 11100xFE
−1281000 00000x80Most negative (8-bit)
420010 10100x2AASCII asterisk
−421101 01100xD6
1000110 01000x64
−1001001 11000x9C

Frequently Asked Questions

A sign-magnitude scheme requires the ALU to check the sign bit before every addition and handle +0 / −0 as separate cases. Two's complement eliminates this: the same adder circuit handles both signed and unsigned addition identically. The MSB carries a weight of −2^(n−1), so overflow detection reduces to comparing carry-in and carry-out of the MSB - a single XOR gate. This is why every mainstream architecture since the IBM System/360 (1964) adopted it.
The tool rejects the input and displays the valid range. For example, an 8-bit signed integer represents −128 to 127. Entering 200 in 8-bit mode is invalid because 200 requires 8 data bits but the sign bit is already consumed. You would need at least 16-bit width. In real hardware, exceeding the range causes integer overflow - the value wraps around silently in C/C++ (undefined behavior for signed types) or throws an exception in languages like Rust or Ada.
No. This is a key advantage over sign-magnitude and ones' complement, which both have distinct +0 and −0 representations. In two's complement, zero is uniquely represented as all bits cleared (e.g., 0000 0000 in 8-bit). Inverting and adding 1 produces a carry that overflows back to 0000 0000. This means the negative range has one extra value: 8-bit covers −128 to +127, not −127 to +127.
Yes. The converter uses BigInt internally for all arithmetic operations. Standard JavaScript Number type loses precision beyond 2^53 − 1 (about 9 × 10^15), but BigInt supports arbitrary-precision integers. A 64-bit signed range of −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 is handled exactly.
Bitwise NOT (~) in most languages flips every bit of the stored value. For a two's complement integer, ~x equals −x − 1. This follows directly from the identity: x + ~x = −1 (all bits set = −1 in two's complement). Therefore, to negate a value, you compute ~x + 1. The converter's step-by-step display shows this invert-then-add-one process explicitly.
Yes. Sign extension replicates the MSB into the new higher bits. For example, −5 in 4-bit is 1011. Extending to 8-bit copies the sign bit: 1111 1011, which still equals −5. The converter automatically applies this if you switch to a wider bit width. Truncating (narrowing) is lossy and may change the value - the tool warns if the value doesn't fit the target width.