Here is some information and goals related to Python bit manipulation, binary manipulation.
Some tasks include:
- Turn "11011000111101..." into bytes, (padded left or right, 0 or 1,) and vice versa.
- Slice ranges of bits
- Rotate bits, addressed by the bit. That is, say: "rotate bits 13-17, wrapping around the edges," or, "rotate bits 13-17, lose bits on the one side, set all new bits to 0."
- Similarly, revert regions of bits, apply logic to regions of bits, etc.,.
- Switch Endianness, with different block sizes.
- Apply operations in block groupings: ex: apply XOR 10101 (5 bits) repeatedly across a field.
Relevant libraries include:
ctypes — A foreign function library for Python — Python Documentation - part of the standard library
python-bitstring - A Python module to help you manage your bits. - Google Project Hosting
Some simple code is at ActiveState Code Recipes: Bit-field manipulation (in Python 2 syntax).
Here are some other examples.
Manipulations
To integer.
To hex string. Note that you don't need to use x8 bits.
To character. 8 bits max.
Characters to integers, but not to strings of 1's and 0's.
