Zero Signup ToolsFree browser tools

Developer Tools

Two's Complement Calculator

Convert signed integers to two's-complement bits at 4, 8, 16, 32, 64, or 128 bits, or decode any binary or hex pattern to its signed and unsigned value.

Bit width

int8_t / uint8_t / i8 / u8

Signed range

-128

to 127

Unsigned range

0

to 255

Sign bit position

bit 7

MSB. 0 means positive, 1 means negative.

Input mode

Type any signed integer in base 10. Examples: -1, -42, 127, -32768.

Bit pattern

Click any bit to flip it. Index 0 is the least-significant bit. Bit 7 is the sign bit (highlighted).

7
6
5
4
3
2
1
0

Signed (two's complement)

-42

The sign bit is 1, so the value reads as negative.

Unsigned

214

Same bits read as a non-negative integer (no sign bit).

Hexadecimal

0xD6

Padded to 2 hex digits for 8-bit alignment.

Octal

0o326

Padded to 3 octal digits. Useful for chmod and legacy formats.

How -42 became its bit pattern

Two's complement of a negative value: take the absolute value, invert every bit, then add 1. The result, masked to the bit width, is what the CPU stores.

Step 1. Binary of |42|

0010 1010

Step 2. Invert every bit

1101 0101

Step 3. Add 1 (with width-masking)

1101 0110

Summary

Width:      8 bits
Binary:     1101 0110
Hex:        0xD6
Octal:      0o326
Signed:     -42
Unsigned:   214

Reference. Common signed-integer extremes

WidthSigned minSigned maxUnsigned max
4-bit-8715
8-bit-128127255
16-bit-327683276765535
32-bit-214748364821474836474294967295
64-bit-9223372036854775808922337203685477580718446744073709551615
128-bit-170141183460469231731687303715884105728170141183460469231731687303715884105727340282366920938463463374607431768211455

All math is computed in your browser using BigInt, so even 128-bit values stay accurate. Your input never leaves the page.

How to use

  1. Pick a bit width: 4, 8, 16, 32, 64, or 128. The width determines the signed range, the sign-bit position, and the padding of the hex and octal output.
  2. Choose an input mode. Signed decimal accepts negative numbers, Unsigned decimal accepts non-negative numbers, and Binary / hex accepts a raw bit pattern with optional 0b, 0x, or 0o prefixes.
  3. Type or paste the value. The bit grid, signed value, unsigned value, hex, and octal forms update instantly.
  4. Click any cell in the bit grid to flip that bit. The sign bit is highlighted in red so you can see how toggling it swings the signed reading.
  5. Use the copy buttons next to each result to copy a single value, or use Copy summary to grab all four formats at once.

About this tool

Two's Complement Calculator turns any signed integer into the bit pattern a CPU stores for it and decodes any raw bit pattern back to the signed and unsigned values it represents. Three input modes cover the cases that actually come up at a debugger, in a textbook, or in a hex dump. Signed decimal accepts any integer between the chosen width's signed minimum and signed maximum (for 8-bit: -128 to 127; for 32-bit: -2,147,483,648 to 2,147,483,647) and emits the canonical two's-complement bit pattern by computing value AND ((1 << width) - 1) in BigInt. Unsigned decimal accepts non-negative integers up to 2^width - 1 and shows what those bits read as when reinterpreted as a signed integer, which is how a debugger's signed and unsigned views diverge for any value above the sign-bit threshold. Binary, hex, and octal mode parses bit patterns directly: 0b prefixes for binary, 0x for hex, 0o for octal, or a bare 0/1 string treated as binary; underscores, commas, and whitespace are stripped so you can paste a grouped value from a debugger. Six bit widths are supported: 4, 8, 16, 32, 64, and 128, which line up with C's int8_t through __int128 and Rust's i8 through i128. All arithmetic uses BigInt, so 128-bit results are bit-exact rather than rounded through a 64-bit float. Each result shows the full bit pattern grouped into nibbles with bit indices, the signed (two's-complement) value, the unsigned value, the hexadecimal form padded to the natural width, the octal form padded similarly, and the signed and unsigned range for the selected width. The bit grid is interactive: clicking any cell flips that bit and reruns the rest of the conversion, useful for seeing exactly how flipping the sign bit changes the value or how setting bits 8 through 15 changes a 32-bit word. When the input is a negative signed value, a derivation panel shows the classic invert-and-add-one procedure step by step. A reference table at the bottom of the page summarises the signed minimum, signed maximum, and unsigned maximum for every supported width so you can use the page as a quick lookup. Everything runs in your browser; the values you type are never uploaded.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsDeveloper Tools