Python Forum
NOT bit-wise operation question - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: NOT bit-wise operation question (/thread-24006.html)



NOT bit-wise operation question - ajayachander - Jan-27-2020

x = 4
y = 1

a = ~x

print(a)

Bit operation on 4 which equates to binary 100
what would be NOT operation on it?

I assumed that it would be binary 011 equating to decimal 3.
but the OpenEDG (edube.org) says the answer is decimal (-5) with no explanation.

Can someone throw a quick explanation as I didn't get its basics right probably.


RE: NOT bit-wise operation question - stranac - Jan-27-2020

This has a pretty good explanation: https://wiki.python.org/moin/BitwiseOperators


RE: NOT bit-wise operation question - ajayachander - Jan-27-2020

(Jan-27-2020, 07:58 AM)stranac Wrote: This has a pretty good explanation: https://wiki.python.org/moin/BitwiseOperators

Thank you Smile

Apparently, a NOT gives -x-1
and in this case, it would be ~x = -100 - 1
~x = - 101 which equals to -5 decimal


Cheers