python-bitstring

Simple construction, analysis and modification of binary data.
Download

python-bitstring Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Scott Griffiths
  • Publisher web site:
  • http://code.google.com/u/python.bitstring/

python-bitstring Tags


python-bitstring Description

Simple construction, analysis and modification of binary data. python-bitstring is a Python module for analysing, constructing and modifying binary data.The underlying binary data can be interpreted as, or constructed from, hexadecimal, octal or binary strings, signed or unsigned integers, and signed or unsigned Exponential Golomb coded integers. It can also be used as and created from plain Python strings.The module is provided with a comprehensive set of unit tests and has been tested with Python 2.4, 2.5 and 2.6.Example usage:Different interpretations, slicing and concatenation:a = BitString(uint=5647, length=16)print a.hex, a.bin, a.uint # 0x160f 0b0001011000001111 5647print a.bin, a.int # 0b101100 -20print (a + '0xf').hex # 0x1fReading data sequentially. Note that the data would more usually come from a read() on a binary file.b = BitString(data='x00x00x01xb3x16x01x20x4f')start_code = b.readbytes(4).hex # 0x000001b3width = b.readbits(12).uint # 352height = b.readbits(12).uint # 288flags = b.readbits(3).bin # 0b010Searching, inserting and deleting:c = BitString(bin='00010010010010001111') # c.hex == '0x1248f'c.findbytealigned('0x48')print c.readbyte() # 0x48c.insert('0b0000') # c.hex == '0x12480f'c.deletebits(bits=8, deletepos=4) # c.hex == '0x180f' Requirements: · Python What's New in This Release: · New cut function · slice function now equivalent to __getitem__ · findall gets a count parameter · Changes to split


python-bitstring Related Software