Signed Number Representations — Sign-Magnitude vs One's vs Two's Complement

Compare the three classic ways of encoding a signed integer in binary — sign-magnitude, one's complement and two's complement — side by side at 8, 16, 32 or 64-bit width. See the binary (sign bit highlighted) and hex of each, why two have a negative zero, and how the ranges differ. Live, in your browser.

Converter Number Systems Updated Jun 21, 2026
How to Use
  1. Pick the bit width — 8, 16, 32 or 64 bits.
  2. Type a signed integer (a leading minus is allowed).
  3. Read the three encodings side by side: sign-magnitude, one's complement and two's complement, each as binary (sign bit highlighted, grouped into nibbles) and hex.
  4. Click any binary or hex value to copy it; the notes panel explains where the encodings agree and where they differ.

Three ways to write a negative number in binary

A fixed block of bits has no minus sign, so a convention has to decide which patterns mean negative. Three classic schemes all reserve the most-significant bit as a sign (1 = negative) and agree exactly on positive numbers, but they encode negatives differently. Sign-magnitude stores the magnitude untouched and just flips the sign bit — the most human-readable, but arithmetic needs special cases. One’s complement negates by inverting every bit. Two’s complement negates by inverting every bit and adding one. This tool lays all three out at the width you choose, with the sign bit highlighted, so you can see at a glance where they coincide and where they part ways.

Negative zero, ranges, and why two’s complement won

The decisive difference is zero. Sign-magnitude and one’s complement each have two zeros: a positive zero (all bits clear) and a distinct negative zero10000000 (0x80) in 8-bit sign-magnitude, and 11111111 (0xFF) in 8-bit one’s complement. That redundant pattern wastes a value and forces comparison hardware to treat two encodings as equal. Two’s complement has a single zero: negating all-zeros wraps straight back to all-zeros, so there is no −0. It spends the freed-up pattern on one extra negative number, giving the famous asymmetric range −128…127 for a byte (versus the symmetric −127…127 of the other two). Combined with the fact that plain binary addition just works across both signs, this is why effectively every modern CPU stores signed integers in two’s complement. All arithmetic here uses JavaScript BigInt, so 64-bit results are exact.

Quick reference

Sign-magnitude −n
set sign bit, keep |n|
One’s complement −n
invert all bits of n
Two’s complement −n
invert all bits, then + 1
Two zeros
SM & 1C: +0 and −0
8-bit −5
SM 0x85 · 1C 0xFA · 2C 0xFB
8-bit range
SM/1C −127…127 · 2C −128…127

About the Signed Number Representations — Sign-Magnitude vs One's vs Two's Complement

Meet the Signed Number Representations — Sign-Magnitude vs One's vs Two's Complement: a free, no-fuss tool for everyday tasks with nothing to install and no sign-up. Compare the three classic ways of encoding a signed integer in binary — sign-magnitude, one's complement and two's complement — side by side at 8, 16, 32 or 64-bit width. See the binary (sign bit highlighted) and hex of each, why two have a negative zero, and how the ranges differ. Live, in your browser.

How it works

Type a value, then pick what you want to change it into. The answer appears straight away. It all happens on your own device, so it is fast and nothing you type is sent away. Just check that you picked the right “from” and “to” so you get the answer you wanted.

Want the deeper story? The Knowledge Base explains the ideas behind the tools in more detail.

Frequently Asked Questions

What is the difference between sign-magnitude, one's complement and two's complement?

All three use the top bit as a sign (1 = negative) and agree exactly on non-negative numbers. They differ in how they encode negatives. Sign-magnitude keeps the magnitude in the remaining bits unchanged and just flips the sign bit. One's complement negates by inverting every bit. Two's complement negates by inverting every bit and adding one. Modern hardware uses two's complement almost universally because ordinary binary addition then works for both signs and there is a single zero.

Why do sign-magnitude and one's complement have two zeros?

In sign-magnitude, +0 is all zeros and −0 is the sign bit set with a zero magnitude (0x80 in 8 bits). In one's complement, −0 is the inversion of all-zeros, i.e. all-ones (0xFF in 8 bits). Both therefore have a distinct +0 and −0, which wastes a bit pattern and complicates comparisons. Two's complement has only one zero (all zeros) — inverting-and-adding-one to zero wraps back to zero — which is one of its key advantages.

Why is the two's complement range asymmetric?

Because two's complement spends its spare bit pattern (the one the other schemes use for −0) on an extra negative value. An 8-bit two's-complement integer covers −128…127: one more negative than positive. Sign-magnitude and one's complement are symmetric (−127…127) but pay for it with a redundant negative zero.

How do I work these out by hand for −5 in 8 bits?

Magnitude 5 = 00000101. Sign-magnitude: set the top bit → 10000101 (0x85). One's complement: invert every bit of +5 → 11111010 (0xFA). Two's complement: invert then add 1 → 11111011 (0xFB). The tool shows all three at once and highlights the sign bit.

Is anything uploaded?

No. Everything is computed in your browser with JavaScript using BigInt, so even 64-bit values are exact and nothing is sent to a server.

How do I use the Signed Number Representations — Sign-Magnitude vs One's vs Two's Complement?

Just type or paste your value. The answer shows up right away — there is no button to press. Change anything and it updates by itself.

Do I need to install or sign up for anything?

Not at all — it runs in the browser with nothing to install and no account. After it loads once, it even works without an internet connection.

Is my information private?

Yes. Everything happens in your browser. Nothing you type is sent to a server or saved anywhere.

Common Use Cases

Learning computer arithmetic

See why two's complement won: one zero, clean addition, and the asymmetric range — all contrasted against the older schemes.

Studying CS / digital logic

A side-by-side answer key for homework on sign-magnitude, one's complement and two's complement encodings at any width.

Reading legacy & exotic formats

A few old machines, checksums and floating-point mantissas use sign-magnitude or one's complement — decode them at the right width.

Understanding negative zero

Spot exactly which bit pattern is −0 in each scheme and confirm two's complement collapses it to a single zero.

Last updated: