Two’s Complement Calculator

Convert signed decimal, binary and hex at 8, 16, 32 or 64 bits. See both signed and unsigned readings and the calculation steps.

Ready · 8-bit integer

Two’s complement calculation steps

    Signed and unsigned decimal show the same bits. Values outside the chosen width are reported without wrapping or truncation.

    /usage

    Decimal to two’s complement, and back

    1. Choose a bit width. The same binary or hex pattern can mean different numbers at different widths.
    2. Enter a signed decimal to encode it, or enter binary or hex to read that pattern as a signed integer. Unsigned decimal shows the other interpretation of the same bits.
    3. Copy any representation, edit individual bits, or open Two’s complement calculation steps to follow the working.

    This 2’s complement calculator uses exact integer arithmetic, including the full 64-bit range. Hex accepts a 0x prefix; binary accepts 0b. Spaces and underscores are accepted in bit patterns, and short patterns are padded with leading zeros. Out-of-range decimal values are reported without widening, wrapping or truncating.

    Bookmark 8-bit, 16-bit, 32-bit or 64-bit conversion. Bookmarks save settings, not entered values. For fractional numbers, use the IEEE 754 floating point converter.

    /examples

    Encode −42 in 8-bit two’s complement

    1. Write the magnitude 42 in binary: 00101010.
    2. Invert every bit: 11010101.
    3. Add one: 11010110, or hex D6.

    The unsigned reading is 214. To decode the signed value, the first bit is 1, so subtract 2^8: 214 − 256 = −42. For a nonnegative number, write its binary value and pad with zeros; no inversion is needed.

    Encoding a negative decimal and negating a raw bit pattern are different tasks. This calculator encodes and decodes the selected signed value; entering 11010110 reads −42 rather than taking its opposite. Negating the minimum signed value overflows the same width.

    /interpretation

    Why FF can mean −1 or 255

    In 8-bit two’s complement the leading bit has weight −128. Therefore 11111111 is −128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = −1. Read as unsigned, those same bits are 255.

    At 16 bits the short input FF is zero-padded to 0000000011111111, which is signed 255. To encode −1 at 16 bits, use FFFF. Padding a short input is not sign extension.

    /ranges

    Signed and unsigned integer ranges

    For n bits, two’s complement ranges from −2^(n−1) to 2^(n−1) − 1. The unsigned range starts at 0 and ends at 2^n − 1. There is one zero and one extra negative value.

    WidthSigned minimumSigned maximumUnsigned maximum
    8-bit-128127255
    16-bit-327683276765535
    32-bit-214748364821474836474294967295
    64-bit-9223372036854775808922337203685477580718446744073709551615

    In 8 bits, 255 is valid in Unsigned decimal and reads as signed −1; it is outside the Signed decimal range. The 64-bit unsigned maximum 18446744073709551615 is handled exactly and reads as signed −1.