Two’s complement of a binary number in C++

By: Prof. Dr. Fazal Rehman | Last updated: February 3, 2024

Write a Program in C++ to find two’s complement of a binary number.

We will ask the user to enter a Binary Number as a string, then the program will  find  2’s complement of the given binary number. 2’s complement of a binary number is another binary number that can be find by the addition of 1 to one’s complement(as previously calculated). Example of binary input: 101010 One’s complement the number: 010110 Example 1: Binary Value:000100 1s Complement = 111011 2s Complement = 111100 Example 2: Binary Value: 110101 1s Complement = 001010 2s Complement = 001011

Leave a Comment

All Copyrights Reserved 2025 Reserved by T4Tutorials