~1 and ~0 giving strange results in python 3 -


And, |, | ^, and ~ all the bitwears in the python are operators & amp ;, ^, and | All are working fine for me - when I take it, say, 1. 0, I get 1. But giving me weird results ~ 1 gives me 2, and ~ 0 gives me 1. Is it because I am using an integer or something? I am running Python 3.

I expect to get from 1 to 0, and 0 to ~ 1 (integer) is this possible?

~ x

Returns the complement of x - the number that you get by switching 1 for 1 and every 0 for 1. This is the same as -x-1

After the last part of that statement:

-1 - 1 actually equal -2 < / P>

and

-0 - 1 actually equal -1


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -