Hex Two's Complement Calculator
The Hex Two's Complement Calculator flips the value you enter in Hex Input to its two's complement — its negation — at the bit width you pick. Click Convert and the result appears in Two's Complement (Hex). When you're debugging a hex dump that's supposed to spell out a message, the hex to text converter decodes it back to readable text instantly.
What Is Two's Complement, and What Does This Hex Calculator Do?
Two's complement is the universally adopted method for representing signed integers inside every modern processor. Rather than reserving a separate flag bit for the sign, it folds the sign directly into the numeric encoding itself. The result is a scheme where addition and subtraction share the same circuit — which is why every CPU, from embedded microcontrollers to 64-bit server chips, relies on it. The text to decimal converter processes your input character by character and lists each one's decimal code point in the output box.
How Two's Complement Encodes Negative Numbers
The key is the most significant bit (MSB). In an n-bit signed word, the sign bit — the leftmost bit — carries a place value of \(-(2^{n-1})\) instead of the usual positive power of two. When the MSB is 0, the number is non-negative; when it's 1, the number is negative. This one rule governs signed interpretation across every bit-width.
To convert a positive value to its negative two's complement encoding, follow two steps:
- Compute the one's complement by inverting every bit — each
0becomes1and each1becomes0. - Add 1 to the result. This final step turns the bit-inverted form into the true two's complement encoding.
Expressed mathematically for an n-bit word:
$$\text{Two's complement} = (\sim X) + 1 = 2^{n} - X$$where \(\sim X\) denotes bitwise NOT and \(X\) is the original unsigned value. This formula also confirms a useful property: the two's complement of zero is zero.
Hexadecimal as Compact Notation for Bit Widths
Hexadecimal isn't a separate encoding scheme here — it's shorthand for groups of four bits. Because \(2^4 = 16\), a single hex digit maps perfectly onto a four-bit nibble. That means an 8-bit byte is always exactly two hex digits, a 16-bit word is four hex digits, a 32-bit double-word is eight hex digits, and a 64-bit quad-word is sixteen hex digits — the exact four bit-width options this calculator supports.
The table below maps every hex digit from 0 to F to its decimal, binary, and octal equivalents:
| Dec | Hex | Bin (nibble) | Oct |
|---|---|---|---|
| 0 | 0 | 0000 | 0 |
| 1 | 1 | 0001 | 1 |
| 2 | 2 | 0010 | 2 |
| 3 | 3 | 0011 | 3 |
| 4 | 4 | 0100 | 4 |
| 5 | 5 | 0101 | 5 |
| 6 | 6 | 0110 | 6 |
| 7 | 7 | 0111 | 7 |
| 8 | 8 | 1000 | 10 |
| 9 | 9 | 1001 | 11 |
| 10 | A | 1010 | 12 |
| 11 | B | 1011 | 13 |
| 12 | C | 1100 | 14 |
| 13 | D | 1101 | 15 |
| 14 | E | 1110 | 16 |
| 15 | F | 1111 | 17 |

How to Compute a Hex Two's Complement, Step by Step
Enter a hex value into Hex Input, choose a bit width — 8-bit, 16-bit, 32-bit, or 64-bit — and click Convert. The calculator treats your value as a fixed-width word at that bit-width and runs every step of the complement conversion automatically, showing the result in Two's Complement (Hex). Here's exactly what happens behind the scenes.
Worked Example: Hex 5A7F at 16-Bit Width
- Hex → bit pattern: Expand each digit using the nibble table above. $$\text{5A7F}_{16} = 0101\;1010\;0111\;1111_2$$
- Check the sign bit: The most significant bit is
0, so the original value reads as positive — unsigned decimal 23167. - Invert all bits (one's complement step): $$\sim 0101\;1010\;0111\;1111 = 1010\;0101\;1000\;0000$$
- Add 1: $$1010\;0101\;1000\;0000 + 1 = 1010\;0101\;1000\;0001$$
- Bit pattern → hex: $$1010\;0101\;1000\;0001_2 = \text{A581}_{16}$$
The calculator's Two's Complement (Hex) field shows A581. To see the same result in decimal, binary, or octal, run A581 through this site's own Hex to Decimal, Hex to Binary, or Hex to Octal converters — A581 is −23167 as a signed 16-bit decimal, 1010010110000001 in binary, and 122601 in octal, and its MSB of 1 confirms it reads as negative in a signed 16-bit context.
Worked Example: 8-Bit Complement of 0x23
- Hex → bit pattern: \(\text{23}_{16} = 0010\;0011_2\)
- Invert all bits: \(\sim 0010\;0011 = 1101\;1100\)
- Add 1: \(1101\;1100 + 1 = 1101\;1101\)
- Bit pattern → hex: \(1101\;1101_2 = \text{DD}_{16}\)
- Interpret as signed decimal: MSB is
1, so the value is negative: \(-128 + 64 + 8 + 4 + 1 = -35\)
Result: 0x23 → two's complement 0xDD = −35 in signed decimal, confirmed by entering DD at 8-bit into this calculator and comparing it against the original 23.
Two's Complement Subtraction: Why This Encoding Exists
Complement Addition Instead of a Separate Subtract Circuit
One of the most useful properties of two's complement is that subtraction becomes plain addition — hardware never needs a dedicated subtraction circuit. To compute hex 0A minus hex 0B (decimal 10 − 11), you instead add 0A to the two's complement of 0B:
- Two's complement of
0x0B(8-bit): invert →1111 0100, add 1 →1111 0101=0xF5(this is −11 in signed 8-bit). - Add to
0x0A: \(0x0A + 0xF5 = 0xFF\) (discarding the carry-out beyond 8 bits). - Interpret the result:
0xFF=1111 1111; MSB is 1, so the signed value is −1 — and indeed \(10 - 11 = -1\). ✓
This is exactly the mechanism that lets a single ALU handle both addition and subtraction — foundational knowledge for assembly-language programming and register-level electronics work.
One's Complement vs Two's Complement
One's complement is simply bitwise inversion with no further step. Its drawback is two representations of zero (0000 0000 and 1111 1111 at 8-bit), which complicates signed arithmetic. Two's complement resolves this by adding 1 after inversion, producing a single, unique zero and a clean rule: to compute A − B, add the two's complement of B to A and discard any carry beyond the word width. That's why two's complement — not one's complement — became the standard signed-integer encoding in virtually every modern processor.
Using Signed Hex Values in Programming Languages
Understanding signed hex values matters the moment you start reading memory dumps, writing embedded firmware, or handling signed integers in any language. In C and C++, int is a signed type on every modern platform. In Python, integers have arbitrary precision, but masking with & 0xFF or & 0xFFFFFFFF manually enforces an 8-bit or 32-bit signed window. In x86 assembly, the NEG instruction computes a register's signed negation in a single clock cycle — exactly the operation this calculator replicates for you at the hex level.
/* C example — observe signed wrapping */
#include <stdint.h>
int8_t a = 0x23; /* +35 */
int8_t b = -a; /* 0xDD = -35, two's complement encoding */
uint8_t u = (uint8_t)b; /* 221 unsigned */
Using this calculator to quickly verify an expected value before or after a bitwise operation catches sign-extension bugs early, before they surface as a confusing off-by-a-lot result deep in a test run.
Common Uses for the Hex Two's Complement Calculator
- Debugging and register inspection: hardware and software engineers inspecting memory-mapped registers, UART payloads, or I²C bus frames need to convert raw hex bytes into their signed decimal meaning quickly.
- Digital electronics design: FPGA designers and PCB engineers working with fixed-point arithmetic need to verify signed representation before synthesizing logic — mis-specifying a bit width here can cost hours of simulation time.
- Learning and coursework: computer science and digital logic students benefit from seeing every bit-inversion and carry step laid out with concrete numbers instead of abstract rules.
Selecting a different bit width — 8-bit, 16-bit, 32-bit, or 64-bit — changes both the representable range and the position of the sign bit, so the exact same hex input can produce a different two's complement result depending on the width you choose. That's worth double-checking any time you copy a hex value between contexts that assume different word sizes.