2's Complement Calculator
Free 2's complement calculator. Encode signed integers, decode binary or hex, add or subtract at 4, 6, 8, 12, 16, or 32 bits with step-by-step working and overflow detection.
Enter any integer between -128 and 127. Negatives are encoded via flip + add 1.
2's Complement Binary
1111 0011
= -13 (decimal) = 0xF3
Bit Layout
8-bit 2's complement • sign bit (MSB) highlighted
Bit weights: MSB (position 7) carries weight −27 in 2's complement; the rest are plain powers of 2.
All Formats
The same value in every representation
Step-by-Step
Exact procedure this calculator followed
- 1
Step 1 — Take the magnitude |-13|
|-13| = 13
- 2
Step 2 — Write 13 in 8-bit binary
0000 1101
- 3
Step 3 — Invert every bit (1's complement)
1111 0010
- 4
Step 4 — Add 1 (2's complement)
1111 0011
- 5
Hexadecimal
0xF3
- 6
Octal
0o363
What Is 2's Complement?
The universal binary encoding for signed integers in modern computers
Two's complement is the way virtually every modern CPU stores signed integers — from tiny 8-bit microcontrollers to 64-bit server processors. It is the answer to a simple question: how do you represent negative numbers in binary so that the same circuitry handles addition and subtraction uniformly?
In an n-bit 2's complement system, the most significant bit (MSB) carries a negative weight of −2n−1 while every other bit keeps its usual positive power of two. That single sign trick gives a contiguous, asymmetric range of [−2n−1, 2n−1 − 1], a unique representation for zero, and the ability to add and subtract signed values with the same hardware adder used for unsigned values.
Four properties make it the winning encoding:
- One unique representation for zero (unlike sign-magnitude or 1's complement)
- Signed addition and subtraction use the same hardware as unsigned
- The sign of a value is immediately readable from the MSB
- Sign extension to a wider register is a simple MSB-copy operation
How to Calculate the 2's Complement
A clear three-step procedure with worked examples
Write |x| in n-bit unsigned binary
Take the absolute value of your number and express it as an n-bit binary integer, zero-padded on the left.
Invert every bit (1's complement)
Flip each 0 to 1 and each 1 to 0. This is the 1's complement of the magnitude.
Add 1 (ignoring any carry past bit n)
Perform a binary +1 on the 1's complement. The result is the n-bit 2's complement of the original negative number. For positives, skip steps 2–3 — the unsigned binary is already the 2's complement form.
Worked examples (8-bit):
−13
|−13| = 13 → 0000 1101
flip → 1111 0010
+1 → 1111 0011
−1
|−1| = 1 → 0000 0001
flip → 1111 1110
+1 → 1111 1111
−128 (INT_MIN)
|−128| = 128 → 1000 0000
flip → 0111 1111
+1 → 1000 0000
+13 (positive)
No flip needed
plain binary →
0000 1101
Signed Ranges by Bit Width
Every common register size and what it can represent
| Bits | Min | Max | Typical use |
|---|---|---|---|
| 4-bit | −8 | 7 | Nibbles, tiny ALUs, intro courses |
| 6-bit | −32 | 31 | Vintage PDP hardware, audio sample cells |
| 8-bit | −128 | 127 | int8_t, char, embedded MCUs, image pixels |
| 12-bit | −2,048 | 2,047 | ADC/DAC converters, audio codecs |
| 16-bit | −32,768 | 32,767 | int16_t, short, WAV audio, game scores |
| 32-bit | −2,147,483,648 | 2,147,483,647 | int32_t, int, Unix time_t (until 2038) |
Asymmetric by design: the range always has one more negative value than positive. The minimum (−2n−1) has no positive counterpart, which is why negating INT_MIN overflows in every width.
Signed vs Unsigned Interpretation
The same 8 bits mean different numbers depending on how you read them
| Binary (8-bit) | Hex | Unsigned | Signed (2's comp) |
|---|---|---|---|
| 0000 0000 | 0x00 | 0 | 0 |
| 0000 1101 | 0x0D | 13 | 13 |
| 0111 1111 | 0x7F | 127 | 127 (max) |
| 1000 0000 | 0x80 | 128 | −128 (min) |
| 1111 0011 | 0xF3 | 243 | −13 |
| 1111 1111 | 0xFF | 255 | −1 |
Key insight: the bit pattern is identical — only the interpretation differs. This is why C's unsigned char and signed char share the same storage but disagree on values ≥ 128.
Arithmetic in 2's Complement
How a single adder handles signed and unsigned uniformly
| Operation | Rule | Example (8-bit) |
|---|---|---|
| Add | Add bit patterns, discard carry past bit n | 45 + (−67) = 0010 1101 + 1011 1101 = 1110 1010 = −22 |
| Subtract | Compute A + (−B), where −B is 2's complement of B | 45 − (−67) = 45 + 67 = 112 |
| Negate | Invert all bits and add 1 (except for INT_MIN) | −(13) = ~0000 1101 + 1 = 1111 0011 = −13 |
| Overflow check | XOR carry-in and carry-out of the MSB | 100 + 50 → 1001 0110 (−106) ← overflow |
| Sign extend | Copy MSB into every new high-order bit | 8-bit 1111 0011 → 16-bit 1111 1111 1111 0011 |
The elegance: the same ripple-carry adder handles signed and unsigned addition. No branching on sign, no separate hardware paths — which is exactly why 2's complement won over sign-magnitude and 1's complement by the late 1960s.
Where 2's Complement Is Used
Real-world domains that rely on this encoding every second of every day
CPU Architectures
x86, ARM, RISC-V, MIPS, PowerPC — every mainstream instruction set stores signed integers in 2's complement. It is baked into ADD, SUB, CMP and every branch-on-sign instruction in silicon.
Programming Languages
int in C, C++, Rust, Go, Java, C# — all 2's complement. C23 and C++20 finally removed legacy sign-magnitude compatibility, making the encoding mandatory in the standards.
Embedded & Firmware
Microcontrollers from AVR to STM32 use 8-, 16-, and 32-bit 2's complement for sensor offsets, motor direction, thermocouple deltas, and every signed register in the datasheet.
Protocols & File Formats
WAV audio samples (signed PCM int16), ELF relocation addends (Elf32_Sword / Elf64_Sxword), and SMBus signed temperature registers all store signed integers as raw 2's complement fixed-width fields.
Assembly & Reverse Engineering
Reading a disassembly of a binary dump means mentally converting bytes like 0xF3 into −13 on the fly. Fluency with flip-and-add-1 is baseline for any low-level debugger.
Computer Science Coursework
From COA and digital logic to compilers and operating systems, every CS syllabus covers 2's complement — and every exam has a "convert −N to 8-bit binary" question.
Common Mistakes & Pro Tips
Avoid the bugs that catch students and seasoned engineers alike
Common Mistakes
Forgetting to pad to full width. A 4-bit −3 is 1101, but at 8 bits it becomes 1111 1101 — always sign-extend when changing register size.
Confusing 1's and 2's complement. The 1's complement of −13 at 8 bits is 1111 0010; the 2's complement is 1111 0011. The extra +1 is the whole point.
Misreading overflow. A carry-out alone doesn't imply signed overflow — compare the carry-in and carry-out of the MSB, or watch whether the result sign contradicts the operand signs.
Negating INT_MIN. In every power-of-two width, −2n−1 has no positive counterpart; negating it wraps back to itself — a classic source of CVEs.
Mixing signed and unsigned interpretation. 1111 0011 is either −13 (signed) or 243 (unsigned). Always know which lens you're looking through.
Pro Tips
Shortcut for negation. An even faster trick: copy bits from the right up to and including the first 1, then flip every bit to the left of it. Produces the same result as flip-and-add-1.
Read the MSB first. Before converting any binary value, look at the leftmost bit. If it's 0, read normally. If it's 1, you know you need to flip-and-add-1 and apply a minus sign.
All-ones is −1. Memorize this: at every bit width, 1111…111 is −1. Then 1111…110 is −2, 1111…101 is −3, and so on. It's the fastest mental conversion for small negatives.
Use unsigned for bit patterns. When you're debugging hex dumps or register values, reach for the unsigned interpretation first — signed meaning is a second-pass reading, not the primary one.
Widen before you compute. If an intermediate result might overflow, sign-extend both operands to a wider register (say 32 → 64 bit) first, compute, then narrow. Prevents the classic INT_MAX + 1 wraparound bug.
Frequently Asked Questions
Common questions and detailed answers
Embed 2's Complement Calculator
Add this calculator to your website or blog for free.
You Might Also Like
Related calculators from other categories
Last updated Apr 16, 2026