|
1 | | - |
2 | | - |
3 | | -.. image:: https://github.com/scott-griffiths/bitstring/blob/master/doc/bitstring_logo_small.png?raw=true |
4 | | - |
5 | | -**bitstring** is a pure Python module designed to help make |
6 | | -the creation and analysis of binary data as simple and natural as possible. |
7 | | - |
8 | | -Bitstrings can be constructed from integers (big and little endian), hex, |
9 | | -octal, binary, strings or files. They can be sliced, joined, reversed, |
10 | | -inserted into, overwritten, etc. with simple functions or slice notation. |
11 | | -They can also be read from, searched and replaced, and navigated in, |
12 | | -similar to a file or stream. |
13 | | - |
14 | | -bitstring is open source software, and has been released under the MIT |
15 | | -licence. |
16 | | - |
17 | | -This module works in both Python 2.7 and Python 3. |
18 | | - |
19 | | -Installation |
20 | | ------------- |
21 | | - |
22 | | -Probably all you need to do is:: |
23 | | - |
24 | | - pip install bitstring |
25 | | - |
26 | | -Alternatively if you have downloaded and unzipped the package then you need to run the |
27 | | -``setup.py`` script with the 'install' argument:: |
28 | | - |
29 | | - python setup.py install |
30 | | - |
31 | | -You may need to run this with root privileges on Unix-like systems. |
32 | | - |
33 | | -Documentation |
34 | | -------------- |
35 | | -The manual for the bitstring module is available here |
36 | | -<https://bitstring.readthedocs.io/en/latest/?>. It contains a walk-through of all |
37 | | -the features and a complete reference section. |
38 | | - |
39 | | -It is also available as a PDF: <https://buildmedia.readthedocs.org/media/pdf/bitstring/latest/bitstring.pdf>. |
40 | | - |
41 | | - |
42 | | -Simple Examples |
43 | | ---------------- |
44 | | -Creation:: |
45 | | - |
46 | | - >>> a = BitArray(bin='00101') |
47 | | - >>> b = Bits(a_file_object) |
48 | | - >>> c = BitArray('0xff, 0b101, 0o65, uint:6=22') |
49 | | - >>> d = pack('intle:16, hex=a, 0b1', 100, a='0x34f') |
50 | | - >>> e = pack('<16h', *range(16)) |
51 | | - |
52 | | -Different interpretations, slicing and concatenation:: |
53 | | - |
54 | | - >>> a = BitArray('0x1af') |
55 | | - >>> a.hex, a.bin, a.uint |
56 | | - ('1af', '000110101111', 431) |
57 | | - >>> a[10:3:-1].bin |
58 | | - '1110101' |
59 | | - >>> 3*a + '0b100' |
60 | | - BitArray('0o0657056705674') |
61 | | - |
62 | | -Reading data sequentially:: |
63 | | - |
64 | | - >>> b = BitStream('0x160120f') |
65 | | - >>> b.read(12).hex |
66 | | - '160' |
67 | | - >>> b.pos = 0 |
68 | | - >>> b.read('uint:12') |
69 | | - 352 |
70 | | - >>> b.readlist('uint:12, bin:3') |
71 | | - [288, '111'] |
72 | | - |
73 | | -Searching, inserting and deleting:: |
74 | | - |
75 | | - >>> c = BitArray('0b00010010010010001111') # c.hex == '0x1248f' |
76 | | - >>> c.find('0x48') |
77 | | - (8,) |
78 | | - >>> c.replace('0b001', '0xabc') |
79 | | - >>> c.insert('0b0000') |
80 | | - >>> del c[12:16] |
81 | | - |
82 | | -Unit Tests |
83 | | ----------- |
84 | | - |
85 | | -The 400+ unit tests should all pass for Python 2.7 and Python 3. To run them, from the `test` |
86 | | -directory run:: |
87 | | - |
88 | | - python -m unittest discover |
89 | | - |
90 | | ----- |
91 | | - |
92 | | -The bitstring module has been released as open source under the MIT License. |
93 | | -Copyright (c) 2006 - 2019 Scott Griffiths |
94 | | - |
95 | | -For more information see the project's homepage on GitHub: |
96 | | -<https://github.com/scott-griffiths/bitstring> |
97 | | - |
| 1 | + |
| 2 | + |
| 3 | +.. image:: /doc/bitstring_logo_small.png |
| 4 | + |
| 5 | +**bitstring** is a pure Python module designed to help make |
| 6 | +the creation and analysis of binary data as simple and natural as possible. |
| 7 | + |
| 8 | +Bitstrings can be constructed from integers (big and little endian), hex, |
| 9 | +octal, binary, strings or files. They can be sliced, joined, reversed, |
| 10 | +inserted into, overwritten, etc. with simple functions or slice notation. |
| 11 | +They can also be read from, searched and replaced, and navigated in, |
| 12 | +similar to a file or stream. |
| 13 | + |
| 14 | +bitstring is open source software, and has been released under the MIT |
| 15 | +licence. |
| 16 | + |
| 17 | +This module works in both Python 2.7 and Python 3. |
| 18 | + |
| 19 | +Installation |
| 20 | +------------ |
| 21 | + |
| 22 | +Probably all you need to do is:: |
| 23 | + |
| 24 | + pip install bitstring |
| 25 | + |
| 26 | +Alternatively if you have downloaded and unzipped the package then you need to run the |
| 27 | +``setup.py`` script with the 'install' argument:: |
| 28 | + |
| 29 | + python setup.py install |
| 30 | + |
| 31 | +You may need to run this with root privileges on Unix-like systems. |
| 32 | + |
| 33 | +Documentation |
| 34 | +------------- |
| 35 | +The manual for the bitstring module is available here |
| 36 | +<https://bitstring.readthedocs.org>. It contains a walk-through of all |
| 37 | +the features and a complete reference section. |
| 38 | + |
| 39 | +It is also available as a PDF at <https://readthedocs.org/projects/bitstring/downloads/pdf/latest/>. |
| 40 | + |
| 41 | + |
| 42 | +Simple Examples |
| 43 | +--------------- |
| 44 | +Creation:: |
| 45 | + |
| 46 | + >>> a = BitArray(bin='00101') |
| 47 | + >>> b = Bits(a_file_object) |
| 48 | + >>> c = BitArray('0xff, 0b101, 0o65, uint:6=22') |
| 49 | + >>> d = pack('intle:16, hex=a, 0b1', 100, a='0x34f') |
| 50 | + >>> e = pack('<16h', *range(16)) |
| 51 | + |
| 52 | +Different interpretations, slicing and concatenation:: |
| 53 | + |
| 54 | + >>> a = BitArray('0x1af') |
| 55 | + >>> a.hex, a.bin, a.uint |
| 56 | + ('1af', '000110101111', 431) |
| 57 | + >>> a[10:3:-1].bin |
| 58 | + '1110101' |
| 59 | + >>> 3*a + '0b100' |
| 60 | + BitArray('0o0657056705674') |
| 61 | + |
| 62 | +Reading data sequentially:: |
| 63 | + |
| 64 | + >>> b = BitStream('0x160120f') |
| 65 | + >>> b.read(12).hex |
| 66 | + '160' |
| 67 | + >>> b.pos = 0 |
| 68 | + >>> b.read('uint:12') |
| 69 | + 352 |
| 70 | + >>> b.readlist('uint:12, bin:3') |
| 71 | + [288, '111'] |
| 72 | + |
| 73 | +Searching, inserting and deleting:: |
| 74 | + |
| 75 | + >>> c = BitArray('0b00010010010010001111') # c.hex == '0x1248f' |
| 76 | + >>> c.find('0x48') |
| 77 | + (8,) |
| 78 | + >>> c.replace('0b001', '0xabc') |
| 79 | + >>> c.insert('0b0000') |
| 80 | + >>> del c[12:16] |
| 81 | + |
| 82 | +Unit Tests |
| 83 | +---------- |
| 84 | + |
| 85 | +The 400+ unit tests should all pass for Python 2.7 and later. To run them, from the `test` |
| 86 | +directory run:: |
| 87 | + |
| 88 | + python -m unittest discover |
| 89 | + |
| 90 | +---- |
| 91 | + |
| 92 | +The bitstring module has been released as open source under the MIT License. |
| 93 | +Copyright (c) 2019 Scott Griffiths |
| 94 | + |
| 95 | +For more information see the project's homepage on GitHub: |
| 96 | +<https://github.com/scott-griffiths/bitstring> |
| 97 | + |
0 commit comments