1’s and 2’s Complement Calculator

Understanding 1’s and 2’s complements is crucial in digital electronics and computer science. These concepts are fundamental to binary arithmetic operations, such as addition, subtraction, and multiplication. In this post, we’ll delve into the intricacies of 1’s and 2’s complements, providing step-by-step explanations and a convenient online 1’s and 2’s complement calculator to assist you in your calculations.

You already learnt about the conversion of binary numbers into decimal numbers. Before we discussed unsigned numbers. Here the difference is that these numbers are negative numbers. Before starting this article you should know how to convert a binary number into decimal number. Here is my article on binary numbers conversion. And the second thing you should know is the complement system, 1’s complement and 2’s complement. Here is my detailed article on representation of numbers.

Key Questions:

There are few steps to follow:

  • First look at MSB, either a positive number or a negative number.
  • If the number is positive (MSB=0) then the conversion technique remains same.
  • If the number is negative (MSB=1) then you have to add (+1) while calculating sum of weights.

Example # 1: Evaluate 1’s and 2’s complement of the given number. 00111101)2

MSB=0; Number is positive.

1’s complement=11000010)2

Lets verify our results for better understanding. Convert the given number and it’s 1’s complement in decimal number system.

00111101)2=(0*27)+(0*26)+(1*25)+(1*24)+(1*23)+(1*22)+(0*21)+(1*20)

                    =(0*128)+(0*64)+(1*32)+(1*16)+(1*8)+(1*4)+(0*2)+(1*1)

                    =0+0+32+16+8+4+0+1

                    =61

Take 1’s complement of this number 00111101, which is given below:

1’s complement=11000010)2

MSB=1; Number is negative. MSB shows both sign and magnitude of the number. We add (+1) also.

11000010)2=(-1*27)+(1*26)+(0*25)+(0*24)+(0*23)+(0*22)+(1*21)+(0*20)+1

                    =(-1*128)+(1*64)+(0*32)+(0*16)+(0*8)+(0*4)+(1*2)+(0*1)+1

                    =  -128+64+2+1

               =-61

Results:

00111101)2=+61)10

11000010)2=-61)10


Example # 2: Evaluate 1’s and 2’s complement of the given number. 10110011)2

This time we have a negative number. MSB=1

1’s complement = 01001100)2

Lets verify our results for better understanding. Convert the given number and it’s 1’s complement in decimal number system.

10110011)2=(-1*27)+(0*26)+(1*25)+(1*24)+(0*23)+(0*22)+(1*21)+(1*20)+1

                    =(-1*128)+(0*64)+(1*32)+(1*16)+(0*8)+(0*4)+(1*2)+(1*1)+1

                    =-128+32+16+2+1+1

                    =-76

Results:

10110011)2 = -76)10

01001100)2 = +76)10


Evaluation of Complement Numbers In Binary Numbers Using 2’s Complement:

The following steps to follow:

  • First look at MSB, either a positive number or a negative number.
  • If number is positive (MSB=0), the conversion technique remains the same.

Example # 1: Evaluate 2’s complement of the given number. 01110101)2

MSB=0; Number is positive.

1’s complement = 10001010)2

2’s complement = 10001011)2

Lets verify. In these two examples, we will evaluate complement of a binary number using 2’s complement and then verify our results by converting the binary numbers into decimal numbers.

The decimal equivalent of the given number is below.

01110101)2=(0*27)+(1*26)+(1*25)+(1*24)+(0*23)+(1*22)+(0*21)+(1*20)

                    =(0*128)+(1*64)+(1*32)+(1*16)+(0*8)+(1*4)+(0*2)+(1*1)

                    =64+32+16+4+1

                    =117

The decimal equivalent of the complement of the given number is below.

The 2’s complement of the given number is 10001011)2.

MSB=1; Number is negative. MSB shows both sign and magnitude of the number.

10001011)2=(-1*27)+(0*26)+(0*25)+(0*24)+(1*23)+(0*22)+(1*21)+(1*20)

                    =(-1*128)+(0*64)+(0*32)+(0*16)+(1*8)+(0*4)+(1*2)+(1*1)

                    =-128+8+2+1

                    =-117

Results:

01110101)2=117)10

10001011)2=-117)10


Example#2: Evaluate 2’s complement of the given number. 10011100)2

This time we have a negative number. MSB=1.

1’s complement = 01100011)2

2’s complement = 01100100)2

Lets verify our results by converting the given binary number into decimal equivalent. The given number is 10011100)2. The decimal equivalent of this number is given below.

10011100)2=(-1*27)+(0*26)+(0*25)+(1*24)+(1*23)+(1*22)+(0*21)+(0*20)

                     =(-1*128)+(0*64)+(0*32)+(1*16)+(1*8)+(1*4)+(0*2)+(0*1)

                     = -128+16+8+4

                     =-100

Similarly, convert the 2’s complement of the given number into its binary equivalent.

01100100)2=(0*27)+(1*26)+(1*25)+(0*24)+(0*23)+(1*22)+(0*21)+(0*20)

                    =(0*128)+(1*64)+(1*32)+(0*16)+(0*8)+(1*4)+(0*2)+(0*1)

                    =64+32+4

                    =100

Results:

10011100)2 = -100)10

01100100)2 = 100)10

Difference Between 2’s Complement and 1’s Complement

Feature1’s Complement2’s Complement
CalculationSimply invert all bits (0 to 1 and 1 to 0).Invert all bits and then add 1 to the result.
Number of ZerosTwo representations: +0 (0000) and -0 (1111).One unique zero (0000).
Hardware EfficiencyComplex, requires “end-around carry” during addition.Simple, uses standard binary addition logic.
Range (for n bits)-(2n-1 – 1) to
+(2n-1 – 1)
-2n-1 to
+(2n-1 – 1)
4-Bit Range-7 to +7-8 to +7
Industry StandardRarely used in modern computing.Used by almost all modern processors.

FAQs

Why do we need 1’s and 2’s complement?

It is an essential technique in binary arithmetic for several reasons.

What is 1’s complement?

1’s complement of a binary number is obtained by flipping all the bits—changing 0s to 1s and 1s to 0s. It provides an inverted version of the binary number.

What is 2’s complement?

2’s complement is obtained by adding 1 to the 1’s complement of a binary number. It is widely used in computers for representing signed integers.

How do you convert a binary number to its 2’s complement?

First, find the 1’s complement by inverting all the bits of the binary number. Then, add 1 to the least significant bit (LSB) of the 1’s complement.

Why is 2’s complement preferred over 1’s complement?

2’s complement is preferred because it eliminates the issue of having two representations for zero (as seen in 1’s complement) and simplifies binary subtraction operations by using the same addition circuitry.

What happens during overflow in 2’s complement arithmetic?

Overflow occurs when the result of an arithmetic operation exceeds the range that can be represented with the given number of bits. In 2’s complement, overflow can be detected when the sign bit of the result is incorrect based on the operation.

Can 1’s complement represent all negative numbers accurately?

1’s complement can represent negative numbers, but it has limitations, such as having two representations for zero (positive and negative zero), which can lead to ambiguity in calculations.

How is subtraction performed using 2’s complement?

Subtraction in 2’s complement is done by adding the 2’s complement of the number to be subtracted. This converts the subtraction problem into an addition problem, which is easier to implement in hardware.

Is there any limitation to using 2’s complement?

The main limitation of 2’s complement is that it has a fixed range based on the number of bits used, which can lead to overflow if calculations exceed this range. However, this is a general limitation of fixed-width binary representations, not just 2’s complement.

What is the range of values in 2’s complement for an n-bit number?

The range for an n-bit number in 2’s complement is from −2n−1 – 2n-1−1.

Why does 2’s complement beat 1’s complement in modern CPUs?

2’s complement is the preferred method in digital electronics because it allows the CPU to perform subtraction using the same hardware used for addition.

Recommended Books:

Digital Design: With an Introduction to the Verilog HDL

Digital Fundamentals 11th ed. Edition

Digital Design and Computer Architecture, RISC-V Edition: RISC-V Edition 1st Edition

Leave a comment

Your email address will not be published. Required fields are marked *