README.txt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ================
  2. bitstring module
  3. ================
  4. **bitstring** is a pure Python module designed to help make
  5. the creation and analysis of binary data as simple and natural as possible.
  6. Bitstrings can be constructed from integers (big and little endian), hex,
  7. octal, binary, strings or files. They can be sliced, joined, reversed,
  8. inserted into, overwritten, etc. with simple functions or slice notation.
  9. They can also be read from, searched and replaced, and navigated in,
  10. similar to a file or stream.
  11. bitstring is open source software, and has been released under the MIT
  12. licence.
  13. This version supports Python 2.6 and later (including Python 3).
  14. For Python 2.4 and 2.5 you should instead download version 1.0.
  15. Documentation
  16. -------------
  17. The manual for the bitstring module is available here
  18. <http://packages.python.org/bitstring>. It contains a walk-through of all
  19. the features and a complete reference section.
  20. It is also available as a PDF as part of the source download.
  21. Installation
  22. ------------
  23. If you have downloaded and unzipped the package then you need to run the
  24. ``setup.py`` script with the 'install' argument::
  25. python setup.py install
  26. You may need to run this with root privileges on Unix-like systems.
  27. If you haven't yet downloaded the package then you can just try::
  28. easy_install bitstring
  29. or ::
  30. pip install bitstring
  31. Simple Examples
  32. ---------------
  33. Creation::
  34. >>> a = BitArray(bin='00101')
  35. >>> b = Bits(a_file_object)
  36. >>> c = BitArray('0xff, 0b101, 0o65, uint:6=22')
  37. >>> d = pack('intle:16, hex=a, 0b1', 100, a='0x34f')
  38. >>> e = pack('<16h', *range(16))
  39. Different interpretations, slicing and concatenation::
  40. >>> a = BitArray('0x1af')
  41. >>> a.hex, a.bin, a.uint
  42. ('1af', '000110101111', 431)
  43. >>> a[10:3:-1].bin
  44. '1110101'
  45. >>> 3*a + '0b100'
  46. BitArray('0o0657056705674')
  47. Reading data sequentially::
  48. >>> b = BitStream('0x160120f')
  49. >>> b.read(12).hex
  50. '160'
  51. >>> b.pos = 0
  52. >>> b.read('uint:12')
  53. 352
  54. >>> b.readlist('uint:12, bin:3')
  55. [288, '111']
  56. Searching, inserting and deleting::
  57. >>> c = BitArray('0b00010010010010001111') # c.hex == '0x1248f'
  58. >>> c.find('0x48')
  59. (8,)
  60. >>> c.replace('0b001', '0xabc')
  61. >>> c.insert('0b0000')
  62. >>> del c[12:16]
  63. Unit Tests
  64. ----------
  65. The 400+ unit tests should all pass for Python 2.6 and later.
  66. ----
  67. The bitstring module has been released as open source under the MIT License.
  68. Copyright (c) 2014 Scott Griffiths
  69. For more information see the project's homepage on Google Code:
  70. <http://python-bitstring.googlecode.com>