EngineerPlay

Two’s complement calculator

−20 in 8-bit two’s complement is 1110 1100: write 20 as 0001 0100, flip every bit to 1110 1011 and add 1. Read as unsigned, the same bits are 236, and 8 bits hold −128 to 127.

Your values

Result

v two’s complement bits
1110 1100
U the bits read as unsigned
236
v_min most negative value
−128
v_max largest value
127

Worked steps

  1. v_min = −2⁷ = −128, v_max = 2⁷ − 1 = 127
  2. 20 → 0001 0100₂
  3. NOT 0001 0100 = 1110 1011
  4. 1110 1011 + 1 → 1110 1100
  5. U = 2⁸ − 20 = 236

Formulas used

The same formulas as the formula sheet and the practice questions; the worked steps print them with your numbers.

Questions

How do you find the two’s complement of a number?

Write the size of the number in binary with the full number of bits, flip every bit and add 1. The top bit of the result is 1 for a negative number.

What range can n bits hold?

From −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1: 8 bits hold −128 to 127, 16 bits hold −32,768 to 32,767. There is one more negative value than positive, because zero takes a pattern with top bit 0.

Why do computers use two’s complement?

The same adder works for positive and negative numbers, and zero has only one pattern. Adding 1110 1100 (−20) and 0001 1110 (30) gives 0000 1010 (10) once the carry out of the top bit is dropped.