Hex Two's Complement Calculator
Hex Two's Complement Calculator. Enter your value into Hex Input, pick a bit width, and the Hex Two's Complement Calculator instantly returns its Two's Complement (Hex). Use the hex to text converter to reveal the original message hidden behind a string of hex character codes.
Need to know whether 0xC7A3 is a big positive number or a small negative one? This Hex Two's Complement Calculator reads a hexadecimal value at the width you choose and gives you the signed decimal result plus the negated hex pattern, so you stop guessing what the top bit means. Below you will find the rules, the formula, a fully worked example and the limits every programmer runs into sooner or later.
Reading Signed Hexadecimal with a Hex Two's Complement Calculator
A hexadecimal string such as C7A3 carries no sign of its own. Whether it means 51,107 or -14,429 depends entirely on how many bits the surrounding system reserves for it. Two's complement is the convention almost every CPU uses to store signed integers, which is why a debugger shows the same hex digits whether the register holds a positive or a negative value. A calculator for this job takes your hex digits, expands them to binary, applies the width you selected and reports what the bit pattern means as a signed decimal.
Under the hood the hexadecimal number is just a compact way of writing binary: each hex digit stands for exactly four bits, called a nibble. That makes the hexadecimal system convenient for people while the machine keeps working in binary. The calculator hides the nibble-by-nibble expansion, but it is worth seeing once, which the sections below do.
The Sign Bit and the Most Significant Bit
The leftmost bit of the chosen width is the sign bit, also called the most significant bit. When it is 0 the value is zero or positive; when it is 1 the value is negative. For hex input you can check it without any binary at all: if the first hex digit is 8 through F, the sign bit is set. That single glance tells you that 9D is negative as a one-byte value, while 3D is not.
Choosing the Bit-Width
The bit-width decides everything. The same digits FF mean 255 in an unsigned byte but -1 when the byte is signed, and 00FF is a plain 255 once you widen it to 16 bits. Always pick the width that matches the register, variable type or protocol field you are decoding.
How to Use the Two's Complement Converter
The two's complement converter works in a few quick steps, and you can follow the same routine on paper when you want to double-check a result: Type a message into the text to decimal converter and click Convert to see its decimal character codes appear in order.
- Type the hexadecimal digits into the input box, with or without the
0xprefix. - Select the width: 8, 16, 32 or 64 bits.
- Press the calculate button to convert the value.
- Read the signed decimal result, the unsigned decimal result, the full binary pattern and the negated hex value.
- Copy whichever form your code, spreadsheet or datasheet needs.
If the digits do not fit in the selected width, widen it first; a value like 1F4A needs at least 16 bits, so it cannot be read as one-byte data without silently dropping the high nibbles.
The Two's Complement Formula for Signed Hex
There are two equivalent ways to get the signed value, and the calculator uses the arithmetic one because it works at any width. For an n-bit pattern with unsigned value U:
$$\text{signed} = \begin{cases} U & \text{if } U < 2^{n-1} \\ U - 2^{n} & \text{if } U \ge 2^{n-1} \end{cases}$$To negate a value, the classic recipe is to flip every bit and add 1:
$$-x = \sim x + 1 \pmod{2^{n}}$$The first step, which is to flip the bits, gives the one's complement. Adding 1 afterwards produces the two's complement. In hex you can flip every digit by subtracting it from F, then increment the final result.
One's Complement vs Two's Complement
A system built on the one's complement alone has two zeros (all zeros and all ones) and needs an end-around carry in addition. Two's complement removes both problems, so addition and subtraction use the same adder circuit whether the numbers are positive or negative, which is a big reason it won as a signed notation in digital electronics and processors alike.
Worked Example: Two's Complement to Decimal for 0xC7A3
Take the value C7A3 at 16 bits. Expand each hex digit into its four-bit nibble, then decide the sign from the leading bit.
| Step | Operation | Result |
|---|---|---|
| 1 | Hex to binary | 1100 0111 1010 0011 |
| 2 | Check the sign bit | Leading 1, so the value is negative |
| 3 | Unsigned decimal value | 51,107 |
| 4 | Subtract 216 (65,536) | -14,429 |
| 5 | Check: invert the bits | 0011 1000 0101 1100 (385C) |
| 6 | Add 1 to get the magnitude | 385D = 14,429 |
Both routes agree: C7A3 as a two-byte signed hex value equals -14,429. Reading it in decimal, the subtraction is simply 51,107 - 65,536. Going the other way, the positive value 0A5C (2,652) is negated by flipping to F5A3 and adding 1, giving F5A4, which is the negative equivalent of 2,652.
Leading Zeros and Sign Extension
Padding changes the meaning if you pad carelessly. A positive number gains leading zeros when you widen it, but a negative number must gain leading ones: the byte 9D (-99) becomes FF9D at 16 bits and FFFFFF9D at 32 bits. Padding 9D with zeros instead would turn -99 into +157.
Signed Hex Ranges for 8-, 16-, 32- and 64-Bit Widths
Every width splits its patterns in half: one half non-negative, the other half negative, with one more negative value than positive. Use this table to know whether a range check is going to pass before you convert anything.
| Width | Minimum (signed) | Maximum (signed) | Hex of minimum | Hex of maximum unsigned |
|---|---|---|---|---|
| 8-bit | -128 | 127 | 80 | FF |
| 16-bit | -32,768 | 32,767 | 8000 | FFFF |
| 32-bit | -2,147,483,648 | 2,147,483,647 | 80000000 | FFFFFFFF |
| 64-bit | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 | 8000000000000000 | FFFFFFFFFFFFFFFF |
Overflow and Fixed-Width Limits
Overflow happens when a result needs more bits than the field allows. Adding 1 to 7F in a signed byte gives 80, which jumps from +127 to -128. The processor does not warn you; it simply wraps around, so wrapped sums always deserve a range check before you trust a result. The same limit applies to the converter: the signed result is only valid when the hex digits fit the width you selected, so a pattern that needs more digits has to be read at the next size up.
Decoding a Motor Position Error with the 2's Complement Calculator
A firmware engineer is tracing why a servo drive faulted during a test run. The log prints the following error as 0xFFFFE2B4, and the drive manual lists the fault limit as 8,192 encoder counts either side of zero. The log gives no sign, so the engineer has to work out which direction the shaft lagged and by how much.
The field is a 32-bit register, so the engineer enters FFFFE2B4 into the calculator with the width set to 32 bits and presses the calculate button. The tool reports an unsigned value of 4,294,959,796, a leading digit F that sets the sign bit, and a signed result of -7,500. That agrees with the quick manual check: 4,294,959,796 minus 4,294,967,296 (which is 232) leaves -7,500.
The sign carries the answer first: the negative result means the shaft trailed the command rather than overshot it. At 4,096 counts per revolution, -7,500 counts is about 1.83 turns behind, inside the 8,192-count limit with 692 counts to spare.
The engineer then decodes the sample that actually tripped the fault, FFFFDFFF, and the same 32-bit conversion returns -8,193, one count beyond the limit. Without the signed decoding, both entries would have looked like harmless four-billion-count readings, and the gain tuning that follows would have had no number to aim at.
Why Programmers Use Two's Complement Representation
Almost every language that has fixed-size integers, including C, C++ and Rust, relies on this encoding for signed types. It shows up in assembly listings, in memory dumps and in the registers you inspect while debugging. Learning to read it by eye saves a lot of time:
- Embedded systems and microcontrollers often send sensor readings as two-byte words, so a temperature drop below zero appears as a value starting with F.
- Programming and debugging output frequently prints a negative
intas eight hex digits starting with FF. - Computer science students use it to learn how binary arithmetic and bitwise operations behave.
- Designers of hardware working with FPGA logic pick widths so that a power of two boundary never clips a signal.
Negative Numbers in Binary Representation
Because the encoding wraps around modulo a power of two, negative numbers are not stored in a special format; they are ordinary bit patterns that happen to be interpreted as below zero. That is why signed notation and unsigned notation can disagree about the very same bits, and why the width must travel with the data.
Hex Two's Complement vs Other Number Systems
A good hex two's complement calculator sits between several base conversions, and it helps to know which one you actually need. Plain base conversion treats the input as an ordinary magnitude: C7A3 becomes 51,107 in decimal and 142643 in octal, with no notion of sign at all. Signed decoding, which is what this 2's complement calculator performs, reinterprets the very same bits so that the top half of the number system reads as negative. Choose the plain route for addresses, colours and checksums; choose the signed route for offsets, deltas, temperatures and anything that can fall below zero.
The same pattern also explains why signed binary strings and signed hex strings convert into one another without any arithmetic. Every hex digit maps to four binary digits, so A is 1010 and 3 is 0011, and the sign decision depends only on the very first bit of the whole string. Whether a spec sheet calls it twos complement, 2's complement or simply "signed", the encoding is the same one.
Fixed-Point Values and Leading 0 Padding
Many embedded signed integer fields are really fixed-point numbers: a raw 16-bit value divided by a power of two. The conversion rule does not change. Decode the raw bits first, then scale. A byte such as 0D written with a leading 0 is positive 13, while the byte F3 is -13, and only after that decode do you divide by 256 or 16 to get the fractional reading your datasheet describes.
Who Needs a Hex Converter Like This
Firmware authors, reverse engineers and computer engineers reach for this tool whenever raw bytes come off a bus, a log file or a debugger and they need the signed decimal behind them. Students meet the same task in a first architecture course, when a quiz asks for the meaning of a hex pattern. If two sources disagree about the same pattern, the cause is nearly always a width or sign assumption rather than an error in the arithmetic. A second run of the hex two’s complement calculator at the other width settles it in seconds, and handling text or octal output is a job for a different converter.
Common Mistakes with Negative Hex Values
Most wrong answers come from three habits. First, forgetting the width, so FFFE is read as 65,534 when it was a -2. Second, converting a signed value with a plain binary to decimal routine that ignores the leading bit, or a decimal to binary routine that writes -5 as -101 instead of a pattern of fixed length. Third, mixing up complementing a number with merely decoding it: decoding FFFE gives -2, while complementing it gives +2.
When you want a second opinion on a pattern, run it through the converter at two different widths and compare. If the answers differ in an unexpected way, the width, not the digits, is the culprit.