Two's Complement Calculator

Choose encode or decode and enter a number or a bit string.

A whole number that fits in the bits chosen.

Bits

The width of the word.

Try

Result

You entered−5, 8 bits-5,\ 8 \text{ bits}

11111011\displaystyle \mathtt{11111011}

Grouped in fours

1111 1011\displaystyle \mathtt{1111\ 1011}

Hexadecimal

FB\displaystyle \mathtt{FB}

Read as an unsigned number

251\displaystyle 251
Show the work
  1. Two's complement

    With 88 bits the leftmost bit is the sign (it is 11 for a negative number), and the range is −128-128 to 127127. A negative number −m-m is stored as 28−m2^{8} - m.

  2. Flip the bits and add 1

    Write the size 55 in 88 bits, flip every bit, then add 11. This is the same as taking 282^{8} minus the size.

    5=00000101flip→11111010add 1→11111011\begin{aligned} 5 &= \mathtt{00000101} \\ \text{flip} &\to \mathtt{11111010} \\ \text{add } 1 &\to \mathtt{11111011} \end{aligned}
  3. Result

    So −5-5 is 11111011\mathtt{11111011} in 88 bits.

Worked examples