Free online tools to generate, calculate,
convert, format, encode, and play.
 

Two's Complement

Convert between signed decimal integers and their two's complement binary representation. Click individual bits to toggle them, or type decimal/binary values directly.


Bit Width
Signed Decimal
Enter a positive or negative integer
Two's Complement Binary
Digits: 0, 1 — MSB is the sign bit

How It Works

Two's complement is the standard method computers use to represent signed integers in binary. The most significant bit (MSB) acts as the sign bit: 0 for positive, 1 for negative.

Positive numbers are stored the same way as unsigned binary. For example, +42 in 8-bit is simply 00101010.

Negative numbers are encoded in three steps:

  1. Write the absolute value in binary
  2. Invert all bits (bitwise NOT) — this gives the one's complement
  3. Add 1 to the result — this gives the two's complement

For example, −42 in 8-bit: 00101010 → invert → 11010101 → +1 → 11010110.

Why two's complement? It allows addition and subtraction to use the same hardware circuit. There is exactly one representation of zero, and the range is asymmetric: an n-bit value can hold −2n−1 to +2n−1−1.


Range Reference

Bits Minimum Maximum C Type
8-128127int8_t / char
16-32,76832,767int16_t / short
32-2,147,483,6482,147,483,647int32_t / int
64-9,223,372,036,854,775,8089,223,372,036,854,775,807int64_t / long long

Embed This Util

You can embed this util on your own site as a widget. Adding ?embed=1 to the URL loads a compact version with just the tool itself; no header, menu, or documentation. Paste this snippet into your HTML:


    

Copy snippet Adjust the height to taste.



Feedback

Help us improve this page by providing feedback, and include your name/email if you want us to reach back. Thank you in advance.


Share with