Two’s Complement Calculator

This two’s complement calculator converts a signed whole number into the exact binary pattern a computer would store it in, using the scheme almost every processor relies on for negative integers. Enter any whole number, positive or negative, then choose a bit width of 8, 16 or 32 bits to match the size you are working with. The calculator returns three results: the two’s complement binary pattern padded to the full width, the equivalent hexadecimal value, and the unsigned decimal value that the same bit pattern represents if read without a sign. Two’s complement works by storing negative numbers as two to the power of the bit width plus the value, which makes the leftmost bit act as a sign bit, 1 for negative and 0 for zero or positive, and lets processors add and subtract without special-case logic for negative numbers. If your number falls outside the range the chosen width can hold, for example beyond minus 128 to 127 at 8 bits, the calculator flags it as out of range rather than showing a wrong answer, so you know to pick a wider width. It suits students learning binary arithmetic, programmers debugging low-level code, and anyone checking how a negative value looks in memory. Try the built-in example of minus 5 at 8 bits to see the working before entering your own numbers.

Calculate.co.nz is proud to be partnered with Health Based Building, a leader in sustainable and health-conscious building innovation. With over a century of experience, they develop high-performance systems like Foreverbreathe Specification, Magnum Board, and Foreverbreathe Paints to support energy-efficient, non-toxic living environments. Their commitment to healthier homes aligns with our belief that informed choices lead to better outcomes for Kiwi households.
Calculate.co.nz partner: Health Based Building
11111011
Hexadecimal0xFB
Unsigned value251

The formula

For a width of w bits, a value v is stored as v if it is zero or positive, or as 2^w + v if it is negative. The pattern fits values from minus 2^(w-1) up to 2^(w-1) minus 1. The leading bit is the sign bit.

Worked example

For minus 5 in 8 bits: 2^8 + (minus 5) = 256 minus 5 = 251, which is 11111011 in binary and FB in hex. Enter -5 with 8-bit selected to confirm.

Frequently asked questions

What is two’s complement?

A way to store signed integers in a fixed number of bits, where a negative number n is held as 2 to the width plus n. It makes addition and subtraction uniform.

What range fits in 8 bits?

Minus 128 to 127. In general minus 2 to the (width minus 1) up to 2 to the (width minus 1) minus 1.

What is the sign bit?

The leftmost bit. If it is 1 the number is negative, if 0 it is zero or positive.

Who this calculator is for

This calculator is for students, programmers and anyone exploring number theory.

What this calculator assumes

  • You enter a signed integer within the range of the chosen width.
  • The width is 8, 16 or 32 bits.
  • Results are shown as the stored bit pattern.

Formula and sources

Related calculators