ones_complement.py
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
#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