Question: Please do the assignment in python and please comment the program. Thank you Given a positive integer, output its 2's complement number. The 2's complement
Given a positive integer, output its 2's complement number. The 2's complement strategy is to flip the bits of its binary representation and then add 1 to the binary representation. You need to write the definition for the method find2sComplement o. Definition for FindComplement() is already provided. 4. Example 1: Input: 5 output: 3 Explanation: The binary representation of 5 is 181 (no leading zero bits), and its co mplement is 818. So you need to add 1 to 810 resulting to e11 i.e. 3 Example 2 Input: 1e Output: 6 Explanation: The binary representation of 10 is 181e (no leading zero bits), and its complenent is 101. So you need to add 1 to 1e1 resulting to 11e 1.e. 6 def find2sComplement (num): #Following method would return the 1's complement of the decimal number. complenent-findcomplenent (num) write code
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
