Playing with binary in Python

While debuging an AVR microcontroller, you need to play with bits. After playing with my calculator I decided to find another way to decode bin/hex etc .. I found a good recipe on ASPN.

Now, this is a little reminder for people (like me) which doesn’t read binary op fluently.

# This will off the bits according to value
x &= ~(value) 

# Here a little reverse: This will set bits on according to value
x |= value

Have fun w/ bits :)

One thought on “Playing with binary in Python

  1. I’ve used python to generate IO-Port bit patterns for debugging the AVR in the simulator. Helped a great deal to solve some tricky timing issues.

Comments are closed.