#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
⚡ FREE · STEP BY STEP

2's Complement Calculator: Signed Binary With Every Step

Convert a signed number to 2's complement, or a binary pattern back to decimal.

  • 🔢 4 to 64 bits
  • 🔁 Both directions
  • 📝 Invert and add 1 shown

How to use the 2's Complement Calculator

  1. 1. Pick a directionChoose decimal to binary, or binary to decimal.
  2. 2. Enter the numberType a decimal number and pick the bit width, or paste a binary pattern.
  3. 3. Check the workingSee invert-and-add-1 steps, plus 1's complement, sign-magnitude, unsigned and hex forms.

How 2's complement works

Computers store signed integers in 2's complement. In n bits, the most significant bit (MSB) has weight −2n−1 and every other bit has its usual positive weight. So 8 bits cover −128 to +127, and 16 bits cover −32,768 to +32,767.

To write a negative number −x in n bits:

  1. Write x in binary using n bits.
  2. Invert every bit. This is the 1's complement.
  3. Add 1. This is the 2's complement.

A quick shortcut: start from the right, copy bits up to and including the first 1, then flip every bit to its left. To read a pattern back, check the MSB. If it is 0, read the number normally. If it is 1, invert, add 1 and put a minus sign in front.

Worked example: −76 in 8 bits

76 in 8-bit binary is 0100 1100. Inverting every bit gives 1011 0011, which is the 1's complement. Adding 1 gives 1011 0100, which is 0xB4. Check with place values: −128 + 32 + 16 + 4 = −76.

The same bits read as an unsigned number give 180. Read as sign-magnitude they give −52, and as 1's complement −75. This is why exam questions always say which form to use.

Why CPUs use 2's complement

There is only one zero (sign-magnitude and 1's complement both have +0 and −0). Addition and subtraction use the same adder circuit, because A − B is A + (2's complement of B). Overflow happens only when two numbers with the same sign give a result with the other sign. For multiplication of signed numbers, see the Booth's multiplication calculator. For base changes, use the number system converter.

Frequently asked questions

What is the range of an n-bit 2's complement number?

From −2^(n−1) to 2^(n−1) − 1. For 8 bits that is −128 to 127. There is one more negative value than positive.

Why can't −128 be shown in 8-bit sign-magnitude?

Sign-magnitude uses one bit for the sign and 7 bits for size, so its range is −127 to +127. Only 2's complement reaches −128.

How do I sign-extend a number to more bits?

Copy the MSB into every new bit on the left. 1011 0100 (−76) in 16 bits is 1111 1111 1011 0100.

Is 2's complement the same as negating a number?

Taking the 2's complement of a pattern gives the pattern of the negative value. Doing it twice gives back the original number.

More free tools

See all free tools