Bit fields in python?

Kwan Lai Cheng laicheng_kwan at innomedia.com.sg
Wed Sep 8 06:43:20 EDT 2010


Thanks everyone for all the suggestions! New to python, so reading up on the struct module & Construct library now, hope to get my problem fixed soon.
  ----- Original Message ----- 

  Bitfields are most commonly used for extreme space optimization - i.e. shoving several variables and flags with carefully limited ranges into a single work. In Python you rarely work this way (where such an optimization is warranted, Python isn't the best tool for the job). However, as in your use case, it is sometimes needed in Python in order to communicate with other devices over the network or some other link.

  In my work with Python and embedded devices I've found the construct library (http://construct.wikispaces.com/) very useful. It allows to you very easily define complex formats for frames/messages on the bit and byte level. The idea is to use construct to encode and decode messages being sent to an embedded device. It works great.

  If you have further questions about this approach, feel free to ask.

  Eli







------------------------------------------------------------------------------


  --
  http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100908/f544cc27/attachment-0001.html>


More information about the Python-list mailing list