Skip to content

Two’s Complement Calculator

Type a signed number to see its two’s complement bits, or paste a bit pattern to read it as a signed value.

Type

8 bits hold −128 to 127.

Width

Two’s complement, 8 bits

1101 0110

−42 in 8-bit two’s complement is 1101 0110 (hex D6).

−1286432168421
  • sign bit, worth −27
  • value bits

Tap a bit to flip it.

Hex
0xD6
Read as unsigned
214

How two’s complement works

In an n-bit two’s complement number the top bit is worth −2ⁿ⁻¹ instead of +2ⁿ⁻¹; every other bit keeps its usual value. In 8 bits the top bit is −128, so 11010110 is −128 + 64 + 16 + 4 + 2 = −42.

To write a negative number by hand, write its absolute value in binary at the full width, flip every bit, and add 1. For −42 in 8 bits: 00101010 → 11010101 → 11010110. The same two steps turn a negative pattern back into its positive value.

The payoff is that addition needs no special cases: adding the patterns for 42 and −42 gives 1 00000000, and dropping the carry out of the top leaves 0. Every value has one pattern (there is no −0), and the range is lopsided by one: −128 to 127 in a byte.

value = −bₙ₋₁×2ⁿ⁻¹ + Σ bᵢ×2ⁱ (i < n−1); −x = (NOT x) + 1

Signed values in 8-bit two’s complement

Positive and negative values as 8-bit patterns, with the same value in 16-bit hex to show sign extension.

Positive and negative values as 8-bit patterns, with the same value in 16-bit hex to show sign extension.
Decimal8-bit binary8-bit hex16-bit hex
1270111 11117F007F
1000110 0100640064
640100 0000400040
420010 10102A002A
10000 0001010001
00000 0000000000
−11111 1111FFFFFF
−21111 1110FEFFFE
−101111 0110F6FFF6
−421101 0110D6FFD6
Show all 14 rows
−641100 0000C0FFC0
−1001001 11009CFF9C
−1271000 000181FF81
−1281000 000080FF80

Range by width

BitsSmallestLargestC type
8−128127int8_t
16−32,76832,767int16_t
32−2,147,483,6482,147,483,647int32_t
64−9,223,372,036,854,775,8089,223,372,036,854,775,807int64_t

Frequently Asked Questions

What is −1 in two’s complement?

All ones: 11111111 in 8 bits, FFFF in 16 bits, FFFFFFFF in 32 bits. Adding 1 to it overflows to all zeros, which is 0.

Why is the range −128 to 127 and not −127 to 127?

Zero takes one of the 128 patterns with a 0 on top, leaving 127 positives, while all 128 patterns with a 1 on top are negative. 10000000 is −128 and has no positive partner in 8 bits.

How do I extend a negative number to more bits?

Copy the sign bit into the new places on the left (sign extension). −42 is D6 in 8 bits and FFD6 in 16 bits; padding with zeros instead would give 214.

What is the difference between ones’ and two’s complement?

Ones’ complement negates by flipping the bits only, which leaves two zeros (00000000 and 11111111). Two’s complement adds 1 after flipping, giving one zero and simpler hardware.