Two's complement converter

A signed number and the bits actually stored for it, in both directions. The same eight bits are −1 or 255 depending only on how you agreed to read them, and the pattern itself does not know which. Nothing you type here leaves your browser — it is worked out on your own device, so there is nothing to send and nothing to log.

Why there is one more negative than positive

An eight-bit signed number runs from −128 to 127. That looks like an off-by-one error and is not.

Eight bits give 256 patterns. One of them has to be zero. If the positives and negatives were symmetrical there would be a pattern left over for negative zero, which is the same number as zero and would mean two ways of writing it — so every comparison would have to check for both. Two's complement spends that spare pattern on one extra negative instead, which is why 127 is the largest positive and −128 the smallest negative, and why −128 has no positive partner.

That has a consequence people meet in real code: negating the smallest negative number gives you itself. In eight bits, −(−128) is −128, because 128 does not fit.

Where to go next