I want to find the complement of a number
For example:
The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.
The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0.
From: https://www.tutorialspoint.com/python/bi...xample.htm
It suggests it just need to use "~". It shows:
But on my python3.5, what I get is:
The resulted number -61 is right, but its binary form is not complement of a.
What happened?
Thanks,
L
For example:
The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.
The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0.
From: https://www.tutorialspoint.com/python/bi...xample.htm
It suggests it just need to use "~". It shows:
1 2 3 4 |
a = 60 bin (a) = 0011 1100 bin (~a) = 1100 0011 = - 61 |
1 2 3 |
a = 60 bin (a) = 0011 1100 bin (~a) = 111101 = - 61 |
What happened?
Thanks,
L