Free Two's Complement Calculator

Encode signed integers, decode raw bit patterns, and inspect width-aware signed, unsigned, binary, hexadecimal, and byte-level views in one place.

Signed Integer Encoding

Two's Complement Calculator

Encode signed integers into two's complement or decode raw binary and hexadecimal patterns back into signed and unsigned values with real width-aware behavior.

The encoder accepts decimal values plus 0b, 0o, and 0x prefixes when you already have a literal from code or firmware docs.

Why width matters

Two's complement only makes sense with a fixed width because the sign bit lives in the highest position of that width. Change the width and you change the legal range, the padded binary form, and the overflow behavior.

Mode

Encode integer

Input

-42

Width

8-bit

Signed range

-128 to 127

Fits width

Yes

Stored signed value

-42

Stored bit pattern

Binary, hexadecimal, signed, and unsigned views

Grouped binary

1101 0110

Hexadecimal

D6

Unsigned decimal

214

Signed decimal

-42

Byte insights

Useful quick checks

Sign bit

Set to 1

Bytes

D6

ASCII preview

.

Step by step

How the encoded pattern was formed

1

Start with the signed input -42 and target a 8-bit width.

2

Write the positive magnitude in 8 bits: 0010 1010.

3

Invert every bit to get the one's complement: 1101 0101.

4

Add 1 to reach the final two's-complement pattern: 1101 0110.

5

Interpret the final bit pattern as unsigned 214 or signed -42 depending on context.

Practical notes

Things to keep in mind

The highest bit is set, so the signed interpretation of this stored pattern is negative.

More Engineering & Debugging Tools

Why this tool matters

Two's complement is simple in theory and surprisingly easy to misread in practice

Engineers run into two's complement whenever a signed integer leaves a comfortable high-level abstraction and turns into a real bit pattern. That happens in assembly, firmware, protocol fields, binary file formats, packet captures, register maps, and debugging sessions where a negative-looking number suddenly appears as a large positive hexadecimal constant. A robust calculator needs to bridge that gap both ways: from a signed integer to its stored representation, and from a raw pattern back to its signed and unsigned meanings.

This calculator focuses on that engineering workflow instead of treating the topic like a classroom trick. You can pick a width, encode a signed value, see the exact stored binary and hex pattern, inspect the sign bit, and read the bytes directly. Or you can start from a binary or hex pattern and decode it with width-aware rules so you can tell whether the data means `246`, `-10`, or something else entirely depending on context.

It is especially useful when you are checking overflow, truncation, type conversion, sign extension, packed protocol fields, or memory dumps. In all of those cases, width is the key detail. A number that fits comfortably in 16 bits may wrap in 8 bits, and a pattern that looks harmless in hex may decode to a negative signed value once the top bit becomes the sign bit. That is exactly why the calculator keeps the width, signed view, unsigned view, and pattern explanation side by side.

Best use cases

Embedded development, systems programming, reverse engineering, packet and protocol inspection, assembly work, and any debugging session where signed integers and raw bytes meet.

What makes it robust

It supports both encoding and decoding, treats width as a first-class setting, explains the transformation step by step, and exposes the signed, unsigned, binary, hex, and byte views together.

How to use it well

Match the width to the actual storage size you care about. If you are reading an 8-bit register, use 8-bit. If you are decoding a 32-bit field from a protocol or memory dump, use 32-bit so the sign bit and range checks stay honest.

FAQ

Common questions about two's complement

What is two's complement used for?

Two's complement is the standard way most modern systems store signed integers. It allows positive and negative numbers to share the same binary addition hardware, which is why it appears in low-level programming, embedded systems, assembly, protocol work, and debugging memory or register values.

Why do I need to choose a width like 8-bit or 16-bit?

Two's complement is always width-dependent. The same value can have different binary representations in 8-bit, 16-bit, 32-bit, or 64-bit form because the sign bit position and total storage space change. A calculator without width is incomplete for real engineering work.

What happens if the value is too large for the selected width?

When a signed integer does not fit inside the chosen width, the stored bit pattern wraps modulo 2^width. That is exactly the kind of behavior engineers need to inspect when debugging overflow, truncation, or type-casting issues.

How do I decode a raw binary or hex pattern back into a signed value?

Treat the input as an unsigned bit pattern first. If the sign bit is 0, the signed value matches the unsigned value. If the sign bit is 1, subtract 2^width from the unsigned value to recover the signed decimal interpretation.