ones_complement.py

roshstar1999
2,063 views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

#to find one's complement

num=5

temp=num

bit=1

while temp:

num=num^bit #Xoring 1 with each bit once in a loop
bit<<=1     
temp>>= 1

print(num)

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content