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 :)



Related Posts

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>