Skip to content
Hex Calculator

Signed Integer to Hex Converter

Encode a signed integer value (int8, int16, int32, int64) as its hex bit pattern — ready for typed code or binary formats.

Hexadecimal result
0xFF
Bit width

Full breakdown (result at 8-bit)

Hexadecimal
0xFF
Decimal (unsigned)
255
Binary
11111111
Octal
377
Signed (8-bit)
-1
Set / clear bits
8 set, 0 clear

How Signed Integers Encode to Hex

Choose the integer type's bit width first, since the encoding depends on it. A positive value converts to hex directly. A negative value gets its magnitude converted to hex, then every bit is inverted and 1 is added — two's complement, the encoding virtually every language and processor uses for signed integer types.

Where This Conversion Actually Comes Up

Writing a Typed Constant Into Code

When you know the decimal value you want but need to hard-code its hex representation for a specific int type — a config default, a test fixture, a protocol constant — this produces the exact bit pattern the compiler would generate.

-1 (int16) -> 0xFFFF

Preparing a Signed Field for a Binary Protocol

Protocols and file formats that declare a field as int16 or int32 need the value two's-complement-encoded at that exact width before it goes into the raw bytes.

-1000 (int32) -> 0xFFFFFC18

Matching a Register's Expected Encoding

Hardware registers that accept a signed calibration or offset value in hex need it encoded at the register's declared width — get the width wrong and the hardware reads a completely different number.

-32768 (int16) -> 0x8000

Common Mistakes Encoding Signed Integers to Hex

  • Choosing a type too narrow for the value — -200 doesn't fit in an int8 (range -128 to 127).
  • Forgetting the invert-and-add-1 steps for negative values.
  • Using a different bit width than the variable's actual declared type, producing a hex pattern that won't match in code.

Why Use This Calculator Instead of Doing It by Hand

  • Handles the invert-and-add-1 encoding for negative values automatically
  • Validates your number against the selected type's actual signed range
  • Runs entirely in your browser — nothing you type gets sent anywhere
  • Outputs a ready-to-paste 0x-prefixed literal for code

Frequently Asked Questions

How do you encode a signed integer as hex?

If the value is positive, convert its magnitude to hex directly. If it's negative, convert the magnitude to hex, invert every bit at the chosen type's width, and add 1 — the standard two's-complement encoding.

Why do I need to pick an integer type before converting?

The encoding depends on the bit width — the same value like -1 produces a different hex pattern as an int8 (0xFF) than as an int32 (0xFFFFFFFF), since the sign extends across however many bits the type has.

What happens if my number doesn't fit the chosen type?

The calculator flags it as out of range — pick a wider integer type so the value fits within what that type can represent as signed.

Can I use this to write a hex literal directly into code?

Yes — the output is a standard 0x-prefixed hex value ready to paste as a constant, matching how most languages expect typed integer literals to be written.

Does entering a positive number work the same way?

Yes — positive values convert the same as an ordinary decimal-to-hex conversion, just validated against the signed range for the type you selected instead of the full unsigned range.

Is this the same as Negative Decimal to Hex?

Same underlying math — this page is framed around programming integer types (int8/int16/int32/int64) specifically, for encoding typed constants rather than general negative arithmetic.

How do I convert an int32 or int16 value to hex specifically?

Pick int32 or int16 as the bit width before converting — the type determines both how many hex digits the result has and where the sign bit sits, so -1 as int16 is 0xFFFF while -1 as int32 is 0xFFFFFFFF.

What about uint16 or uint32 — do I use this tool for those too?

Only if the value could be negative. For a value you know is always non-negative, use the Hex Unsigned Integer Calculator instead — it skips the sign handling this tool does for signed types.