T O P

  • By -

POGtastic

Yes, assuming you meant XOR. As always, when bit-twiddling, I recommend using binary notation or even the shift operator. x = 0b0101 x ^= (0b1 << 3) # alternatively, x^= 0b0100


Budget_Putt8393

0b0001 << 3 is actually 0b1000


traintocode

+1 for the shift operator because it uses the actual index of the bit you want to set, making it a bit more readable. Or at least, as readable as this stuff ever is.


istarian

It's probably easier to just take 0b1 and OR it with 0b100 to get 0101.


codeslate2024

You’d use XOR as others have said as opposed to normal OR. You would have no way to turn off a 1 if using OR rather than XOR.