Python Forum
NOT bit-wise operation question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NOT bit-wise operation question
#1
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.
Reply
#2
This has a pretty good explanation: https://wiki.python.org/moin/BitwiseOperators
Reply
#3
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner's String Operation question docboy 6 3,492 Sep-30-2018, 05:49 PM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020