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).
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
| Width | Signed min | Signed max | Unsigned max |
|---|---|---|---|
| 4-bit | -8 | 7 | 15 |
| 8-bit | -128 | 127 | 255 |
| 16-bit | -32768 | 32767 | 65535 |
| 32-bit | -2147483648 | 2147483647 | 4294967295 |
| 64-bit | -9223372036854775808 | 9223372036854775807 | 18446744073709551615 |
| 128-bit | -170141183460469231731687303715884105728 | 170141183460469231731687303715884105727 | 340282366920938463463374607431768211455 |
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
- 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.
- 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.
- Type or paste the value. The bit grid, signed value, unsigned value, hex, and octal forms update instantly.
- 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.
- 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
Bitwise Calculator
Bit-by-bit AND, OR, XOR, NOT, shift, and rotate over two operands at any width.
Open tool
ConverterNumber Base Converter
Binary, octal, decimal, hex, and custom-base conversion with two's complement.
Open tool
DeveloperIEEE 754 Converter
Decimal to IEEE 754 bits and back, for single (32-bit) and double (64-bit) floats.
Open tool
ConverterBinary Translator
Bidirectional text and binary translation with UTF-8 byte breakdown.
Open tool
DeveloperIPv6 Expander and Compressor
Expand, compress, classify, and derive reverse DNS for any IPv6 address with optional zone and CIDR prefix.
Open tool
DeveloperChmod Calculator
Convert chmod values between octal, symbolic (rwxr-xr-x), and clickable owner, group, and other checkboxes.
Open tool