Two's Complement Converter

Convert signed decimal, binary or hex to two's complement at 4, 8, 16, 32 or 64 bits.

Binary (two’s complement)

Hexadecimal
Signed decimal
Unsigned decimal
More views of this pattern
Inverted bits (one’s complement)
Negated (two’s complement of this pattern)
Sign bit (MSB)

Invert and add one

    No uploads. Your files stay on your device.

    Free forever, no sign-up, no cookies. Buy me a coffee

    How it works

    Type a value, say how it should be read (signed decimal, unsigned decimal, raw binary bits or hexadecimal) and pick a bit width. Every other view of the same 4, 8, 16, 32 or 64-bit pattern updates as you type: the two’s complement bits, the hex byte pattern, what the pattern means as a signed integer and as an unsigned one, the inverted bits, the negated value and the sign bit. The step list underneath shows the classic hand method — write the magnitude in binary, flip every bit, add one — on your actual number, so you can check homework or a datasheet by eye.

    This is two’s complement exactly as fixed-width machine integers use it: a value v is stored as v mod 2n, so the top bit carries the sign and the signed range is −2n−1 to 2n−1−1. It is the representation required for signed integers by ISO/IEC 9899:2024 (C23) and by the Java Language Specification, which is why -1 is 0xFF in a byte, 0xFFFF in a 16-bit word and 0xFFFFFFFF in a 32-bit int. The one asymmetry is deliberate: the most negative value has no positive twin, so negating −128 in 8 bits gives −128 back, and the page says so when that happens.

    All the arithmetic runs on JavaScript BigInt values inside your browser, so 64-bit patterns are exact rather than rounded through a double, and nothing you type is uploaded, logged or sent anywhere.

    Frequently asked questions

    How do you calculate two's complement?

    Write the magnitude of the number in binary at your chosen width, invert every bit, then add 1. For -42 in 8 bits: 42 is 0010 1010, inverting gives 1101 0101, and adding 1 gives 1101 0110, which is 0xD6. The converter shows those three steps on whatever number you type, so you can check your own working.

    What is the two's complement of -1?

    Every bit is set, at any width: 1111 1111 (0xFF) in 8 bits, 0xFFFF in 16 bits, 0xFFFFFFFF in 32 bits and 0xFFFFFFFFFFFFFFFF in 64 bits. That is why a signed -1 read as unsigned comes out as 255, 65535, 4294967295 or 18446744073709551615.

    Why can't -128 be negated in 8 bits?

    A signed 8-bit range runs from -128 to 127, so the most negative value has no positive twin. Inverting 1000 0000 and adding 1 gives 1000 0000 again, still -128. The converter flags that case as an overflow instead of quietly returning the wrong answer, and the same asymmetry applies at every width.

    Report a bug