[Two Easy Methods] How to Find 2’s Complement?
If you have given a decimal number, convert it into a binary number. Now you got the binary number.
Note: If you are C programmer, you can find this easiest program to convert decimal into binary in C.
Following are the methods you can use to find 2’s complement of any number.
How to find 2’s complement?
Method #1: using Bit Addition
- Find 1’s complement of the number. This conversion can be done easily by changing 0’s into 1’s and 1’s into 0’s.
- Add one to the result using binary addition.
Remember, For this method, it is necessary to know bit manipulation.
If you are not good at understanding binary bits, follow the simple trick given below.
Method #2: Shortcut to find 2’s complement
It will be easy to demonstrate and to understand it by taking an example. Let’s find the 2’s complement of binary number 001100.
Follow the simple steps described in the image.
- Traverse binary bits from right to left
- Find the first 1 bit
- Reverse every bit after first 1’s
With this logic and bit manipulation, you can also write a program in C and Java to find the 2’s complement of the given number.
2’s complement of the number will be helpful in many bit operations. So do remember how to find 2’s complement of any number. In the upcoming article, I will write a note about the significance of 2’s complement and where it is useful.
Do you know any other method to find the 2’s complement of the number? If yes, please share with us in the comment.