bitarray 3.12.0__cp315-cp315-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1180 @@
1
+ Metadata-Version: 2.4
2
+ Name: bitarray
3
+ Version: 3.12.0
4
+ Summary: efficient arrays of booleans -- C extension
5
+ Home-page: https://github.com/ilanschnell/bitarray
6
+ Author: Ilan Schnell
7
+ Author-email: ilanschnell@gmail.com
8
+ License: PSF-2.0
9
+ Classifier: Development Status :: 6 - Mature
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: C
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.7
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Programming Language :: Python :: 3.15
23
+ Classifier: Programming Language :: Python :: Free Threading :: 2 - Beta
24
+ Classifier: Topic :: Utilities
25
+ Requires-Python: >=3.7
26
+ License-File: LICENSE
27
+ Dynamic: author
28
+ Dynamic: author-email
29
+ Dynamic: classifier
30
+ Dynamic: description
31
+ Dynamic: home-page
32
+ Dynamic: license
33
+ Dynamic: license-file
34
+ Dynamic: requires-python
35
+ Dynamic: summary
36
+
37
+ bitarray: efficient arrays of booleans
38
+ ======================================
39
+
40
+ This library provides an object type which efficiently represents an array
41
+ of booleans. Bitarrays are sequence types and behave very much like usual
42
+ lists. Eight bits are represented by one byte in a contiguous block of
43
+ memory. The user can select between two representations: little-endian
44
+ and big-endian. All functionality is implemented in C.
45
+ Methods for accessing the machine representation are provided, including the
46
+ ability to import and export buffers. This allows creating bitarrays that
47
+ are mapped to other objects, including memory-mapped files.
48
+
49
+
50
+ Key features
51
+ ------------
52
+
53
+ * The bit-endianness can be specified for each bitarray object, see below.
54
+ * Sequence methods: slicing (including slice assignment and deletion),
55
+ operations ``+``, ``*``, ``+=``, ``*=``, the ``in`` operator, ``len()``
56
+ * Bitwise operations: ``~``, ``&``, ``|``, ``^``, ``<<``, ``>>`` (as well as
57
+ their in-place versions ``&=``, ``|=``, ``^=``, ``<<=``, ``>>=``).
58
+ * `Free-threading support <https://github.com/ilanschnell/bitarray/blob/master/doc/free_threading.rst>`__
59
+ (for GIL-disabled CPython 3.14 and later)
60
+ * Fast methods for encoding and decoding variable-length prefix codes.
61
+ * Bitarray objects support the `buffer protocol <https://github.com/ilanschnell/bitarray/blob/master/doc/buffer.rst>`__
62
+ (both importing and exporting buffers).
63
+ * Efficient packing and unpacking for interoperability with byte-oriented
64
+ objects such as NumPy arrays.
65
+ * Pickling and unpickling of bitarray objects.
66
+ * Immutable ``frozenbitarray`` objects which are hashable
67
+ * Fast searching for bits and bit patterns
68
+ * ``bitfields`` sub-module for packing and unpacking fixed-width
69
+ `bit-field structures <https://github.com/ilanschnell/bitarray/blob/master/doc/bitfields.rst>`__
70
+ * Type hinting
71
+ * Extensive test suite with over 700 unit tests
72
+ * Utility module ``bitarray.util``:
73
+
74
+ * conversion to and from hexadecimal strings
75
+ * generating random bitarrays
76
+ * pretty printing
77
+ * conversion to and from integers
78
+ * creating Huffman codes
79
+ * `compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__
80
+ * run-length encoding
81
+ * serialization and deserialization
82
+ * various count functions
83
+ * other helpful functions
84
+
85
+
86
+ Installation
87
+ ------------
88
+
89
+ Python wheels are are available on PyPI for all major platforms and Python
90
+ versions. Which means you can simply:
91
+
92
+ .. code-block:: shell-session
93
+
94
+ $ pip install bitarray
95
+
96
+ Once you have installed the package, you may want to test it:
97
+
98
+ .. code-block:: shell-session
99
+
100
+ $ python -c 'import bitarray; bitarray.test()'
101
+ bitarray is installed in: /Users/ilan/bitarray/bitarray
102
+ sys.prefix: /Users/ilan/miniforge
103
+ bitarray version: 3.12.0
104
+ sys.version: 3.14.5 (main, May 20 2026) [Clang 20.1.8]
105
+ sys.abiflags: ''
106
+ sys._is_gil_enabled(): True
107
+ pointer size: 64 bit
108
+ sizeof(size_t): 8
109
+ sizeof(bitarrayobject): 80
110
+ HAVE_BUILTIN_BSWAP64: 1
111
+ default bit-endianness: big
112
+ machine byte-order: little
113
+ Py_GIL_DISABLED: 0
114
+ Py_DEBUG: 0
115
+ DEBUG: 0
116
+ .....................................s...................................
117
+ ..........s.....................................s........................
118
+ ......s.........................................................
119
+ ----------------------------------------------------------------------
120
+ Ran 711 tests in 0.196s
121
+
122
+ OK (skipped=4)
123
+
124
+ The ``test()`` function is part of the API. It will return
125
+ a ``unittest.runner.TextTestResult`` object, such that one can verify that
126
+ all tests ran successfully by:
127
+
128
+ .. code-block:: python
129
+
130
+ import bitarray
131
+ assert bitarray.test().wasSuccessful()
132
+
133
+
134
+ Usage
135
+ -----
136
+
137
+ As mentioned above, bitarray objects behave very much like lists, so
138
+ there is not too much to learn. The biggest difference from list
139
+ objects (except that bitarray are obviously homogeneous) is the ability
140
+ to access the machine representation of the object.
141
+ When doing so, the bit-endianness is of importance; this issue is
142
+ explained in detail in the section below. Here, we demonstrate the
143
+ basic usage of bitarray objects:
144
+
145
+ .. code-block:: python
146
+
147
+ >>> from bitarray import bitarray
148
+ >>> a = bitarray() # create empty bitarray
149
+ >>> a.append(1)
150
+ >>> a.extend([1, 0])
151
+ >>> a
152
+ bitarray('110')
153
+ >>> x = bitarray(2 ** 20) # bitarray of length 1048576 (initialized to 0)
154
+ >>> len(x)
155
+ 1048576
156
+ >>> bitarray('1001 011') # initialize from string (whitespace is ignored)
157
+ bitarray('1001011')
158
+ >>> lst = [1, 0, False, True, True]
159
+ >>> a = bitarray(lst) # initialize from iterable
160
+ >>> a
161
+ bitarray('10011')
162
+ >>> a[2] # indexing a single item will always return an integer
163
+ 0
164
+ >>> a[2:4] # whereas indexing a slice will always return a bitarray
165
+ bitarray('01')
166
+ >>> a[2:3] # even when the slice length is just one
167
+ bitarray('0')
168
+ >>> a.count(1)
169
+ 3
170
+ >>> a.remove(0) # removes first occurrence of 0
171
+ >>> a
172
+ bitarray('1011')
173
+
174
+ Like lists, bitarray objects support slice assignment and deletion:
175
+
176
+ .. code-block:: python
177
+
178
+ >>> a = bitarray(50)
179
+ >>> a.setall(0) # set all elements in a to 0
180
+ >>> a[11:37:3] = 9 * bitarray('1')
181
+ >>> a
182
+ bitarray('00000000000100100100100100100100100100000000000000')
183
+ >>> del a[12::3]
184
+ >>> a
185
+ bitarray('0000000000010101010101010101000000000')
186
+ >>> a[-6:] = bitarray('10011')
187
+ >>> a
188
+ bitarray('000000000001010101010101010100010011')
189
+ >>> a += bitarray('000111')
190
+ >>> a[9:]
191
+ bitarray('001010101010101010100010011000111')
192
+
193
+ In addition, slices can be assigned to booleans, which is easier (and
194
+ faster) than assigning to a bitarray in which all values are the same:
195
+
196
+ .. code-block:: python
197
+
198
+ >>> a = 20 * bitarray('0')
199
+ >>> a[1:15:3] = True
200
+ >>> a
201
+ bitarray('01001001001001000000')
202
+
203
+ This is easier and faster than:
204
+
205
+ .. code-block:: python
206
+
207
+ >>> a = 20 * bitarray('0')
208
+ >>> a[1:15:3] = 5 * bitarray('1')
209
+ >>> a
210
+ bitarray('01001001001001000000')
211
+
212
+ Note that in the latter we have to create a temporary bitarray whose length
213
+ must be known or calculated. Another example of assigning slices to Booleans,
214
+ is setting ranges:
215
+
216
+ .. code-block:: python
217
+
218
+ >>> a = bitarray(30)
219
+ >>> a[:] = 0 # set all elements to 0 - equivalent to a.setall(0)
220
+ >>> a[10:25] = 1 # set elements in range(10, 25) to 1
221
+ >>> a
222
+ bitarray('000000000011111111111111100000')
223
+
224
+ As of bitarray version 2.8, indices may also be lists of arbitrary
225
+ indices (like in NumPy), or bitarrays that are treated as masks,
226
+ see `Bitarray indexing <https://github.com/ilanschnell/bitarray/blob/master/doc/indexing.rst>`__.
227
+
228
+
229
+ Bitwise operators
230
+ -----------------
231
+
232
+ Bitarray objects support the bitwise operators ``~``, ``&``, ``|``, ``^``,
233
+ ``<<``, ``>>`` (as well as their in-place versions ``&=``, ``|=``, ``^=``,
234
+ ``<<=``, ``>>=``). The behavior is very much what one would expect:
235
+
236
+ .. code-block:: python
237
+
238
+ >>> a = bitarray('101110001')
239
+ >>> ~a # invert
240
+ bitarray('010001110')
241
+ >>> b = bitarray('111001011')
242
+ >>> a ^ b # bitwise XOR
243
+ bitarray('010111010')
244
+ >>> a &= b # inplace AND
245
+ >>> a
246
+ bitarray('101000001')
247
+ >>> a <<= 2 # in-place left-shift by 2
248
+ >>> a
249
+ bitarray('100000100')
250
+ >>> b >> 1 # return b right-shifted by 1
251
+ bitarray('011100101')
252
+
253
+ The C language does not specify the behavior of negative shifts and
254
+ of left shifts larger or equal than the width of the promoted left operand.
255
+ The exact behavior is compiler/machine specific.
256
+ This Python bitarray library specifies the behavior as follows:
257
+
258
+ * the length of the bitarray is never changed by any shift operation
259
+ * blanks are filled by 0
260
+ * negative shifts raise ``ValueError``
261
+ * shifts larger or equal to the length of the bitarray result in
262
+ bitarrays with all values 0
263
+
264
+ It is worth noting that (regardless of bit-endianness) the bitarray left
265
+ shift (``<<``) always shifts towards lower indices, and the right
266
+ shift (``>>``) always shifts towards higher indices.
267
+
268
+
269
+ Bit-endianness
270
+ --------------
271
+
272
+ For many purposes the bit-endianness is not of any relevance to the end user
273
+ and can be regarded as an implementation detail of bitarray objects.
274
+ However, there are use cases when the bit-endianness becomes important.
275
+ These use cases involve explicitly reading and writing the bitarray buffer
276
+ using ``.tobytes()``, ``.frombytes()``, ``.tofile()`` or ``.fromfile()``,
277
+ importing and exporting buffers. Also, a number of utility functions
278
+ in ``bitarray.util`` will return different results depending on
279
+ bit-endianness, such as ``ba2hex()`` or ``ba2int``.
280
+ To better understand this topic, please read `bit-endianness <https://github.com/ilanschnell/bitarray/blob/master/doc/endianness.rst>`__.
281
+
282
+
283
+ Buffer protocol
284
+ ---------------
285
+
286
+ Bitarray objects support the buffer protocol. They can both export their
287
+ own buffer, as well as import another object's buffer. To learn more about
288
+ this topic, please read `buffer protocol <https://github.com/ilanschnell/bitarray/blob/master/doc/buffer.rst>`__. There is also an example that shows how
289
+ to memory-map a file to a bitarray: `mmapped-file.py <https://github.com/ilanschnell/bitarray/blob/master/examples/mmapped-file.py>`__
290
+
291
+
292
+ Variable-length prefix codes
293
+ ----------------------------
294
+
295
+ The ``.encode()`` method takes a dictionary mapping symbols to bitarrays
296
+ and an iterable, and extends the bitarray object with the encoded symbols
297
+ found while iterating. For example:
298
+
299
+ .. code-block:: python
300
+
301
+ >>> d = {'H':bitarray('111'), 'e':bitarray('0'),
302
+ ... 'l':bitarray('110'), 'o':bitarray('10')}
303
+ ...
304
+ >>> a = bitarray()
305
+ >>> a.encode(d, 'Hello')
306
+ >>> a
307
+ bitarray('111011011010')
308
+
309
+ Note that the string ``'Hello'`` is an iterable, but the symbols are not
310
+ limited to characters, in fact any immutable Python object can be a symbol.
311
+ Taking the same dictionary, we can apply the ``.decode()`` method which will
312
+ return an iterable of the symbols:
313
+
314
+ .. code-block:: python
315
+
316
+ >>> list(a.decode(d))
317
+ ['H', 'e', 'l', 'l', 'o']
318
+ >>> ''.join(a.decode(d))
319
+ 'Hello'
320
+
321
+ Symbols are not limited to being characters.
322
+ The above dictionary ``d`` can be efficiently constructed using the function
323
+ ``bitarray.util.huffman_code()``. I also wrote `Huffman coding in Python
324
+ using bitarray <http://ilan.schnell-web.net/prog/huffman/>`__ for more
325
+ background information.
326
+
327
+ When the codes are large, and you have many decode calls, most time will
328
+ be spent creating the (same) internal decode tree objects. In this case,
329
+ it will be much faster to create a ``decodetree`` object, which can be
330
+ passed to bitarray's ``.decode()`` method, instead of passing the prefix
331
+ code dictionary to those methods itself:
332
+
333
+ .. code-block:: python
334
+
335
+ >>> from bitarray import bitarray, decodetree
336
+ >>> t = decodetree({'a': bitarray('0'), 'b': bitarray('1')})
337
+ >>> a = bitarray('0110')
338
+ >>> list(a.decode(t))
339
+ ['a', 'b', 'b', 'a']
340
+
341
+ The sole purpose of the immutable ``decodetree`` object is to be passed
342
+ to bitarray's ``.decode()`` method.
343
+
344
+
345
+ Frozenbitarrays
346
+ ---------------
347
+
348
+ A ``frozenbitarray`` object is very similar to the bitarray object.
349
+ The difference is that this a ``frozenbitarray`` is immutable, and hashable,
350
+ and can therefore be used as a dictionary key:
351
+
352
+ .. code-block:: python
353
+
354
+ >>> from bitarray import frozenbitarray
355
+ >>> key = frozenbitarray('1100011')
356
+ >>> {key: 'some value'}
357
+ {frozenbitarray('1100011'): 'some value'}
358
+ >>> key[3] = 1
359
+ Traceback (most recent call last):
360
+ ...
361
+ TypeError: frozenbitarray is immutable
362
+
363
+
364
+ Reference
365
+ =========
366
+
367
+ bitarray version: 3.12.0 -- `change log <https://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst>`__
368
+
369
+ In the following, ``item`` and ``value`` are usually a single bit -
370
+ an integer 0 or 1.
371
+
372
+ Also, ``sub_bitarray`` refers to either a bitarray, or an ``item``.
373
+
374
+
375
+ The bitarray object:
376
+ --------------------
377
+
378
+ ``bitarray(initializer=0, /, endian='big', buffer=None)`` -> bitarray
379
+ Return a new bitarray object whose items are bits initialized from
380
+ the optional initializer, and bit-endianness.
381
+ The initializer may be one of the following types:
382
+ a.) ``int`` bitarray, initialized to zeros, of given length
383
+ b.) ``bytes`` or ``bytearray`` to initialize buffer directly
384
+ c.) ``str`` of 0s and 1s, ignoring whitespace and "_"
385
+ d.) iterable of integers 0 or 1.
386
+
387
+ Optional keyword arguments:
388
+
389
+ ``endian``: Specifies the bit-endianness of the created bitarray object.
390
+ Allowed values are ``big`` and ``little`` (the default is ``big``).
391
+ The bit-endianness affects the buffer representation of the bitarray.
392
+
393
+ ``buffer``: Any object which exposes a buffer. When provided, ``initializer``
394
+ cannot be present (or has to be ``None``). The imported buffer may be
395
+ read-only or writable, depending on the object type.
396
+
397
+ New in version 2.3: optional ``buffer`` argument
398
+
399
+ New in version 3.4: allow initializer ``bytes`` or ``bytearray`` to set buffer directly
400
+
401
+
402
+ bitarray methods:
403
+ ^^^^^^^^^^^^^^^^^
404
+
405
+ ``all()`` -> bool
406
+ Return ``True`` when all bits in bitarray are 1.
407
+ ``a.all()`` is a faster version of ``all(a)``.
408
+
409
+
410
+ ``any()`` -> bool
411
+ Return ``True`` when any bit in bitarray is 1.
412
+ ``a.any()`` is a faster version of ``any(a)``.
413
+
414
+
415
+ ``append(item, /)``
416
+ Append ``item`` to the end of the bitarray.
417
+
418
+
419
+ ``buffer_info()`` -> BufferInfo
420
+ Return named tuple with following fields:
421
+
422
+ 0. ``address``: memory address of buffer
423
+ 1. ``nbytes``: buffer size (in bytes)
424
+ 2. ``endian``: bit-endianness as a string
425
+ 3. ``padbits``: number of pad bits
426
+ 4. ``alloc``: allocated memory for buffer (in bytes)
427
+ 5. ``readonly``: memory is read-only (bool)
428
+ 6. ``imported``: buffer is imported (bool)
429
+ 7. ``exports``: number of buffer exports
430
+
431
+ New in version 3.7: return named tuple
432
+
433
+
434
+ ``bytereverse(start=0, stop=<end of buffer>, /)``
435
+ For each byte in byte-range(``start``, ``stop``) reverse bits in-place.
436
+ The start and stop indices are given in terms of bytes (not bits) and
437
+ are interpreted like slice bounds and clipped to the buffer size.
438
+ Also note that this method only changes the buffer; it does not change the
439
+ bit-endianness of the bitarray object. Pad bits are left unchanged such
440
+ that two consecutive calls will always leave the bitarray unchanged.
441
+
442
+ New in version 2.2.5: optional start and stop arguments
443
+
444
+ New in version 3.9.1: clip arguments instead of raising ``IndexError``
445
+
446
+
447
+ ``clear()``
448
+ Remove all items from bitarray.
449
+
450
+ New in version 1.4
451
+
452
+
453
+ ``copy()`` -> bitarray
454
+ Return copy of bitarray (with same bit-endianness).
455
+
456
+
457
+ ``count(value=1, start=0, stop=<end>, step=1, /)`` -> int
458
+ Number of occurrences of ``value`` bitarray within ``[start:stop:step]``.
459
+ Optional arguments ``start``, ``stop`` and ``step`` are interpreted in
460
+ slice notation, meaning ``a.count(value, start, stop, step)`` equals
461
+ ``a[start:stop:step].count(value)``.
462
+ The ``value`` may also be a sub-bitarray. In this case non-overlapping
463
+ occurrences are counted within ``[start:stop]`` (``step`` must be 1).
464
+
465
+ New in version 1.1.0: optional start and stop arguments
466
+
467
+ New in version 2.3.7: optional step argument
468
+
469
+ New in version 2.9: add non-overlapping sub-bitarray count
470
+
471
+
472
+ ``decode(code, /)`` -> decodeiterator
473
+ Given a prefix code (a dict mapping symbols to bitarrays, or ``decodetree``
474
+ object), decode content of bitarray and return an iterator over
475
+ corresponding symbols.
476
+ The prefix code length cannot exceed 256 bits.
477
+
478
+ See also: `Bitarray 3 transition <https://github.com/ilanschnell/bitarray/blob/master/doc/bitarray3.rst>`__
479
+
480
+ New in version 3.0: returns iterator (equivalent to past ``.iterdecode()``)
481
+
482
+ New in version 3.9: returns public ``decodeiterator`` object
483
+
484
+
485
+ ``encode(code, iterable, /)``
486
+ Given a prefix code (a dict mapping symbols to bitarrays),
487
+ iterate over the iterable object with symbols, and extend bitarray
488
+ with corresponding bitarray for each symbol.
489
+
490
+
491
+ ``extend(iterable, /)``
492
+ Append items from iterable to the end of the bitarray.
493
+ If ``iterable`` is a (Unicode) string, each ``0`` and ``1`` are appended as
494
+ bits (ignoring whitespace and underscore).
495
+
496
+ New in version 3.4: allow ``bytes`` object
497
+
498
+
499
+ ``fill(m=8, /)`` -> int
500
+ Add zeros to the end of the bitarray, such that the length will be
501
+ a multiple of the positive integer ``m``, and return the number of bits
502
+ added (in ``range(m)``).
503
+
504
+ New in version 3.12: add optional alignment argument
505
+
506
+
507
+ ``find(sub_bitarray, start=0, stop=<end>, /, right=False)`` -> int
508
+ Return lowest (or rightmost when ``right=True``) index where sub_bitarray
509
+ is found, such that sub_bitarray is contained within ``[start:stop]``.
510
+ Return -1 when sub_bitarray is not found.
511
+
512
+ New in version 2.1
513
+
514
+ New in version 2.9: add optional keyword argument ``right``
515
+
516
+
517
+ ``frombytes(bytes, /)``
518
+ Extend bitarray with raw bytes from a bytes-like object.
519
+ Each added byte will add eight bits to the bitarray.
520
+
521
+ New in version 2.5.0: allow bytes-like argument
522
+
523
+
524
+ ``fromfile(f, n=-1, /)``
525
+ Extend bitarray with up to ``n`` bytes read from file object ``f`` (or any
526
+ other binary stream that supports a ``.read()`` method, e.g. ``io.BytesIO``).
527
+ Each read byte will add eight bits to the bitarray. When ``n`` is omitted
528
+ or negative, reads and extends all data until EOF.
529
+ When ``n`` is non-negative but exceeds the available data, ``EOFError`` is
530
+ raised. However, the available data is still read and extended.
531
+
532
+
533
+ ``index(sub_bitarray, start=0, stop=<end>, /, right=False)`` -> int
534
+ Return lowest (or rightmost when ``right=True``) index where sub_bitarray
535
+ is found, such that sub_bitarray is contained within ``[start:stop]``.
536
+ Raises ``ValueError`` when sub_bitarray is not present.
537
+
538
+ New in version 2.9: add optional keyword argument ``right``
539
+
540
+
541
+ ``insert(index, value, /)``
542
+ Insert ``value`` into bitarray before ``index``.
543
+
544
+
545
+ ``invert(index=<all bits>, /)``
546
+ Invert bits in-place. When ``index`` is omitted, invert all bits.
547
+ When ``index`` is an integer, invert the single bit at index.
548
+ When ``index`` is a slice, invert the selected bits.
549
+
550
+ New in version 1.5.3: optional index argument
551
+
552
+
553
+ ``pack(bytes, /)``
554
+ Extend bitarray from a bytes-like object, where each byte corresponds
555
+ to a single bit. The byte ``b'\x00'`` maps to bit 0 and all other bytes
556
+ map to bit 1.
557
+
558
+ This method, as well as the ``.unpack()`` method, are meant for efficient
559
+ transfer of data between bitarray objects to other Python objects (for
560
+ example NumPy's ndarray object) which have a different memory view.
561
+
562
+ New in version 2.5.0: allow bytes-like argument
563
+
564
+
565
+ ``pop(index=-1, /)`` -> item
566
+ Remove and return item at ``index`` (default last).
567
+ Raises ``IndexError`` if index is out of range.
568
+
569
+
570
+ ``remove(value, /)``
571
+ Remove the first occurrence of ``value``.
572
+ Raises ``ValueError`` if value is not present.
573
+
574
+
575
+ ``reverse()``
576
+ Reverse all bits in bitarray (in-place).
577
+
578
+
579
+ ``rotate(k=1, /)``
580
+ Rotate bitarray in-place by ``k`` positions.
581
+ Positive ``k`` rotates right, negative ``k`` rotates left.
582
+
583
+ When bitarray ``a`` is not empty, rotating one step to the right is
584
+ equivalent to ``a.insert(0, a.pop())``, and rotating one step to the left
585
+ is equivalent to ``a.append(a.pop(0))``.
586
+ The same convention is used by the ``.rotate()`` method of
587
+ the ``collections.deque`` object.
588
+
589
+ New in version 3.9
590
+
591
+
592
+ ``search(sub_bitarray, start=0, stop=<end>, /, right=False)`` -> iterator
593
+ Return iterator over indices where sub_bitarray is found, such that
594
+ sub_bitarray is contained within ``[start:stop]``.
595
+ The indices are iterated in ascending order (from lowest to highest),
596
+ unless ``right=True``, which will iterate in descending order (starting with
597
+ rightmost match).
598
+
599
+ For example, ``a.search(1)`` is the easiest (and most efficient) way
600
+ to create an iterator over all active indices in ``a``.
601
+
602
+ See also: `Bitarray 3 transition <https://github.com/ilanschnell/bitarray/blob/master/doc/bitarray3.rst>`__
603
+
604
+ New in version 2.9: optional start and stop arguments - add optional keyword argument ``right``
605
+
606
+ New in version 3.0: returns iterator (equivalent to past ``.itersearch()``)
607
+
608
+
609
+ ``setall(value, /)``
610
+ Set all elements in bitarray to ``value``.
611
+ Note that ``a.setall(value)`` is equivalent to ``a[:] = value``.
612
+
613
+
614
+ ``sort(reverse=False)``
615
+ Sort all bits in bitarray (in-place).
616
+
617
+
618
+ ``to01(group=0, sep=' ')`` -> str
619
+ Return bitarray as (Unicode) string of ``0``s and ``1``s.
620
+ The bits are grouped into ``group`` bits (default is no grouping).
621
+ When grouped, the string ``sep`` is inserted between groups
622
+ of ``group`` characters, default is a space.
623
+
624
+ New in version 3.3: optional ``group`` and ``sep`` arguments
625
+
626
+
627
+ ``tobytes()`` -> bytes
628
+ Return the bitarray buffer (pad bits are set to zero).
629
+ ``a.tobytes()`` is equivalent to ``bytes(a)``
630
+
631
+
632
+ ``tofile(f, /)``
633
+ Write bitarray buffer to file object ``f``.
634
+
635
+
636
+ ``tolist()`` -> list
637
+ Return bitarray as list of integers.
638
+ ``a.tolist()`` equals ``list(a)``.
639
+
640
+ Note that the list object being created will require 32 or 64 times more
641
+ memory (depending on the machine architecture) than the bitarray object,
642
+ which may cause a memory error if the bitarray is very large.
643
+
644
+
645
+ ``unpack(zero=b'\x00', one=b'\x01')`` -> bytes
646
+ Return bytes that contain one byte for each bit in the bitarray,
647
+ using the specified mapping.
648
+
649
+
650
+ bitarray attributes:
651
+ ^^^^^^^^^^^^^^^^^^^^
652
+
653
+ Attributes were added in version 2.6.
654
+
655
+ ``endian`` -> str
656
+ bit-endianness as Unicode string
657
+
658
+ New in version 3.4: replaces former ``.endian()`` method
659
+
660
+
661
+ ``nbytes`` -> int
662
+ buffer size in bytes
663
+
664
+
665
+ ``padbits`` -> int
666
+ number of pad bits
667
+
668
+
669
+ ``readonly`` -> bool
670
+ bool indicating whether buffer is read-only
671
+
672
+
673
+ decodeiterator methods:
674
+ ^^^^^^^^^^^^^^^^^^^^^^^
675
+
676
+ ``skipbits(n, /)`` -> bitarray
677
+ Skip over the next ``n`` bits and return them.
678
+ Raises ``ValueError`` if count is out of range.
679
+
680
+ New in version 3.9
681
+
682
+
683
+ decodeiterator attributes:
684
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
685
+
686
+ ``index`` -> int
687
+ current bit position to be decoded by subsequent ``next``
688
+
689
+ New in version 3.9
690
+
691
+
692
+ decodetree methods:
693
+ ^^^^^^^^^^^^^^^^^^^
694
+
695
+ ``nodes()`` -> tuple
696
+ Return tuple with number of:
697
+
698
+ 0. incomplete nodes (pointing to a single child node)
699
+ 1. complete nodes (pointing to two child nodes)
700
+ 2. leaf nodes (pointing to a symbol)
701
+
702
+ New in version 3.10
703
+
704
+
705
+ ``todict()`` -> dict
706
+ Return a dict mapping the symbols to frozenbitarrays. This dict is a
707
+ reconstruction of the code dict which the object was created with.
708
+
709
+ New in version 3.10
710
+
711
+
712
+ Other objects:
713
+ --------------
714
+
715
+ ``frozenbitarray(initializer=0, /, endian='big', buffer=None)`` -> frozenbitarray
716
+ Return a ``frozenbitarray`` object. Initialized the same way a ``bitarray``
717
+ object is initialized. A ``frozenbitarray`` is immutable and hashable,
718
+ and may therefore be used as a dictionary key.
719
+
720
+ New in version 1.1
721
+
722
+
723
+ ``decodetree(code, /)`` -> decodetree
724
+ Given a prefix code (a dict mapping symbols to bitarrays),
725
+ create a binary tree object to be passed to ``.decode()``.
726
+ The prefix code length cannot exceed 256 bits.
727
+
728
+ New in version 1.6
729
+
730
+
731
+ Functions defined in the `bitarray` module:
732
+ -------------------------------------------
733
+
734
+ ``bits2bytes(n, /)`` -> int
735
+ Return the number of bytes necessary to store n bits.
736
+
737
+
738
+ ``get_default_endian()`` -> str
739
+ Return the default bit-endianness for new bitarray objects being created.
740
+
741
+ New in version 1.3
742
+
743
+
744
+ ``test(verbosity=1)`` -> TextTestResult
745
+ Run self-test, and return ``unittest.runner.TextTestResult`` object.
746
+
747
+
748
+ Functions defined in `bitarray.util` module:
749
+ --------------------------------------------
750
+
751
+ This sub-module was added in version 1.2.
752
+
753
+ ``any_and(a, b, /)`` -> bool
754
+ Efficient implementation of ``any(a & b)``.
755
+
756
+ New in version 2.7
757
+
758
+
759
+ ``ba2base(n, bitarray, /, group=0, sep=' ')`` -> str
760
+ Return a string containing the base ``n`` ASCII representation of
761
+ the bitarray. Allowed values for ``n`` are 2, 4, 8, 16, 32 and 64.
762
+ The bitarray has to have a length divisible by 1, 2, 3, 4, 5 or 6
763
+ respectively.
764
+ For ``n=32`` the RFC 4648 Base32 alphabet is used, and for ``n=64`` the
765
+ standard base 64 alphabet is used.
766
+ When grouped, the string ``sep`` is inserted between groups
767
+ of ``group`` characters, default is a space.
768
+
769
+ See also: `Bitarray representations <https://github.com/ilanschnell/bitarray/blob/master/doc/represent.rst>`__
770
+
771
+ New in version 1.9
772
+
773
+ New in version 3.3: optional ``group`` and ``sep`` arguments
774
+
775
+
776
+ ``ba2hex(bitarray, /, group=0, sep=' ')`` -> hexstr
777
+ Return a string containing the hexadecimal representation of
778
+ the bitarray (which has to be multiple of 4 in length).
779
+ When grouped, the string ``sep`` is inserted between groups
780
+ of ``group`` characters, default is a space.
781
+
782
+ New in version 3.3: optional ``group`` and ``sep`` arguments
783
+
784
+
785
+ ``ba2int(bitarray, /, signed=False)`` -> int
786
+ Convert the given bitarray to an integer.
787
+ The bit-endianness of the bitarray is respected.
788
+ ``signed`` indicates whether two's complement is used to represent the integer.
789
+
790
+
791
+ ``base2ba(n, asciistr, /, endian=None)`` -> bitarray
792
+ Bitarray of base ``n`` ASCII representation.
793
+ Allowed values for ``n`` are 2, 4, 8, 16, 32 and 64.
794
+ For ``n=32`` the RFC 4648 Base32 alphabet is used, and for ``n=64`` the
795
+ standard base 64 alphabet is used. ASCII whitespace is ignored.
796
+
797
+ See also: `Bitarray representations <https://github.com/ilanschnell/bitarray/blob/master/doc/represent.rst>`__
798
+
799
+ New in version 1.9
800
+
801
+ New in version 3.3: ignore whitespace
802
+
803
+
804
+ ``byteswap(a, n=<buffer size>, /)``
805
+ Reverse every ``n`` consecutive bytes of ``a`` in-place.
806
+ By default, all bytes are reversed. Note that ``n`` is **not** limited
807
+ to 2, 4 or 8, but can be any positive integer.
808
+ Also, ``a`` may be any object that exposes a writable buffer.
809
+ Nothing about this function is specific to bitarray objects.
810
+
811
+ We should mention that Python's ``array.array`` object has a
812
+ method ``.byteswap()`` with similar functionality. However, unlike
813
+ bitarray's ``util.byteswap()`` function, this method is limited to
814
+ swapping 2, 4, or 8 consecutive bytes.
815
+
816
+ New in version 3.4
817
+
818
+
819
+ ``canonical_decode(bitarray, count, symbol, /)`` -> iterator
820
+ Decode bitarray using canonical Huffman decoding tables
821
+ where ``count`` is a sequence containing the number of symbols of each length
822
+ and ``symbol`` is a sequence of symbols in canonical order.
823
+
824
+ See also: `Canonical Huffman Coding <https://github.com/ilanschnell/bitarray/blob/master/doc/canonical.rst>`__
825
+
826
+ New in version 2.5
827
+
828
+
829
+ ``canonical_huffman(dict, /)`` -> tuple
830
+ Given a frequency map, a dictionary mapping symbols to their frequency,
831
+ calculate the canonical Huffman code. Returns a tuple containing:
832
+
833
+ 0. the canonical Huffman code as a dict mapping symbols to frozenbitarrays
834
+ 1. a list containing the number of symbols of each code length
835
+ 2. a list of symbols in canonical order
836
+
837
+ Note: the two lists may be used as input for ``canonical_decode()``.
838
+
839
+ See also: `Canonical Huffman Coding <https://github.com/ilanschnell/bitarray/blob/master/doc/canonical.rst>`__
840
+
841
+ New in version 2.5
842
+
843
+ New in version 3.10: return a codedict mapping to frozenbitarrays
844
+
845
+
846
+ ``correspond_all(a, b, /)`` -> tuple
847
+ Return tuple with counts of: ~a & ~b, ~a & b, a & ~b, a & b
848
+
849
+ New in version 3.4
850
+
851
+
852
+ ``count_and(a, b, /)`` -> int
853
+ Return ``(a & b).count()`` in a memory efficient manner,
854
+ as no intermediate bitarray object gets created.
855
+
856
+
857
+ ``count_n(a, n, value=1, /)`` -> int
858
+ Return lowest index ``i`` for which ``a[:i].count(value) == n``.
859
+ Raises ``ValueError`` when ``n`` exceeds total count (``a.count(value)``).
860
+
861
+ New in version 2.3.6: optional value argument
862
+
863
+
864
+ ``count_or(a, b, /)`` -> int
865
+ Return ``(a | b).count()`` in a memory efficient manner,
866
+ as no intermediate bitarray object gets created.
867
+
868
+
869
+ ``count_xor(a, b, /)`` -> int
870
+ Return ``(a ^ b).count()`` in a memory efficient manner,
871
+ as no intermediate bitarray object gets created.
872
+
873
+ This is also known as the Hamming distance.
874
+
875
+
876
+ ``deserialize(bytes, /)`` -> bitarray
877
+ Return a bitarray given a bytes-like representation such as returned
878
+ by ``serialize()``.
879
+
880
+ See also: `Bitarray representations <https://github.com/ilanschnell/bitarray/blob/master/doc/represent.rst>`__
881
+
882
+ New in version 1.8
883
+
884
+ New in version 2.5.0: allow bytes-like argument
885
+
886
+
887
+ ``gen_primes(n, /, endian=None, odd=False)`` -> bitarray
888
+ Generate a bitarray of length ``n`` in which active indices are prime numbers.
889
+ By default (``odd=False``), active indices correspond to prime numbers directly.
890
+ When ``odd=True``, only odd prime numbers are represented in the resulting
891
+ bitarray ``a``, and ``a[i]`` corresponds to ``2*i+1`` being prime or not.
892
+
893
+ Apart from working with prime numbers, this function is useful for
894
+ testing, as it provides a simple way to create a well-defined bitarray
895
+ of any length.
896
+
897
+ New in version 3.7
898
+
899
+
900
+ ``hex2ba(hexstr, /, endian=None)`` -> bitarray
901
+ Bitarray of hexadecimal representation. hexstr may contain any number
902
+ (including odd numbers) of hex digits (upper or lower case).
903
+ ASCII whitespace is ignored.
904
+
905
+ New in version 3.3: ignore whitespace
906
+
907
+
908
+ ``huffman_code(dict, /, endian=None)`` -> dict
909
+ Given a frequency map, a dictionary mapping symbols to their frequency,
910
+ calculate the Huffman code, i.e. a dict mapping those symbols to
911
+ frozenbitarrays (with given bit-endianness). Note that the symbols are not
912
+ limited to being strings. Symbols may be any hashable object.
913
+
914
+ New in version 3.10: return a codedict mapping to frozenbitarrays
915
+
916
+
917
+ ``int2ba(int, /, length=None, endian=None, signed=False)`` -> bitarray
918
+ Convert the given integer to a bitarray (with given bit-endianness,
919
+ and no leading (big-endian) / trailing (little-endian) zeros), unless
920
+ the ``length`` of the bitarray is provided. An ``OverflowError`` is raised
921
+ if the integer is not representable with the given number of bits.
922
+ ``signed`` determines whether two's complement is used to represent the integer,
923
+ and requires ``length`` to be provided.
924
+
925
+
926
+ ``intervals(bitarray, /)`` -> iterator
927
+ Compute all uninterrupted intervals of 1s and 0s, and return an
928
+ iterator over tuples ``(value, start, stop)``. The intervals are guaranteed
929
+ to be in order, and their size is always non-zero (``stop - start > 0``).
930
+
931
+ New in version 2.7
932
+
933
+
934
+ ``ones(n, /, endian=None)`` -> bitarray
935
+ Create a bitarray of length ``n``, with all values ``1``, and optional
936
+ bit-endianness (``little`` or ``big``).
937
+
938
+ New in version 2.9
939
+
940
+
941
+ ``parity(a, /)`` -> int
942
+ Return parity of bitarray ``a``.
943
+ ``parity(a)`` is equivalent to ``a.count() % 2`` but more efficient.
944
+
945
+ New in version 1.9
946
+
947
+
948
+ ``pprint(bitarray, /, stream=None, group=8, indent=4, width=80)``
949
+ Pretty-print bitarray object to ``stream``, defaults to ``sys.stdout``.
950
+ By default, bits are grouped in bytes (8 bits), and 64 bits per line.
951
+ Non-bitarray objects are printed using ``pprint.pprint()``.
952
+
953
+ New in version 1.8
954
+
955
+
956
+ ``random_k(n, /, k, endian=None)`` -> bitarray
957
+ Return (pseudo-) random bitarray of length ``n`` with ``k`` elements
958
+ set to one. Mathematically equivalent to setting (in a bitarray of
959
+ length ``n``) all bits at indices ``random.sample(range(n), k)`` to one.
960
+ The random bitarrays are reproducible when calling Python's ``random.seed()``
961
+ with a specific seed value.
962
+
963
+ New in version 3.6
964
+
965
+
966
+ ``random_p(n, /, p=0.5, endian=None)`` -> bitarray
967
+ Return (pseudo-) random bitarray of length ``n``, where each bit has
968
+ probability ``p`` of being one (independent of any other bits). Mathematically
969
+ equivalent to ``bitarray((random() < p for _ in range(n)), endian)``, but much
970
+ faster for large ``n``. The random bitarrays are reproducible when calling
971
+ Python's ``random.seed()`` with a specific seed value.
972
+
973
+ This function requires Python 3.12 or higher, as it depends on the standard
974
+ library function ``random.binomialvariate()``. Raises ``NotImplementedError``
975
+ when Python version is too low.
976
+
977
+ See also: `Random Bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/random_p.rst>`__
978
+
979
+ New in version 3.5
980
+
981
+
982
+ ``rl_decode(stream, /, endian=None)`` -> bitarray
983
+ Decode a run-length encoded bitarray from a binary stream (an integer
984
+ iterator, or bytes-like object), and return the decoded bitarray.
985
+ This function consumes only one bitarray and leaves the remaining stream
986
+ untouched. Use ``rl_encode()`` for encoding.
987
+
988
+ See also: `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
989
+
990
+ New in version 3.11
991
+
992
+
993
+ ``rl_encode(bitarray, /)`` -> bytes
994
+ Return the run-length encoded binary representation of a bitarray.
995
+ This representation may be useful for bitarrays with long runs of
996
+ identical bits. Use ``rl_decode()`` for decoding.
997
+
998
+ See also: `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
999
+
1000
+ New in version 3.11
1001
+
1002
+
1003
+ ``sc_decode(stream, /)`` -> bitarray
1004
+ Decompress binary stream (an integer iterator, or bytes-like object) of a
1005
+ sparse compressed (``sc``) bitarray, and return the decoded bitarray.
1006
+ This function consumes only one bitarray and leaves the remaining stream
1007
+ untouched. Use ``sc_encode()`` for compressing (encoding).
1008
+
1009
+ See also: `Compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__, `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
1010
+
1011
+ New in version 2.7
1012
+
1013
+
1014
+ ``sc_encode(bitarray, /)`` -> bytes
1015
+ Compress a bitarray using sparse encoding and return its binary
1016
+ representation. This representation is useful for efficiently storing
1017
+ sparse bitarrays. Use ``sc_decode()`` for decompressing (decoding).
1018
+
1019
+ See also: `Compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__, `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
1020
+
1021
+ New in version 2.7
1022
+
1023
+
1024
+ ``sc_stat(stream)`` -> dict
1025
+ Scan a stream produced by ``sc_encode()`` and return a dictionary containing
1026
+ its bit-endianness (``endian``), length (``nbits``), and the number of blocks
1027
+ of each type (``blocks``). ``blocks`` is a list such that ``blocks[i]`` is the
1028
+ number of blocks of type ``i``.
1029
+
1030
+ Like ``sc_decode()``, it consumes one encoded bitarray and leaves remaining
1031
+ input untouched.
1032
+
1033
+ See also: `Compression of sparse bitarrays <https://github.com/ilanschnell/bitarray/blob/master/doc/sparse_compression.rst>`__
1034
+
1035
+ New in version 3.11
1036
+
1037
+
1038
+ ``serialize(bitarray, /)`` -> bytes
1039
+ Return a serialized representation of the bitarray, which may be passed to
1040
+ ``deserialize()``. It efficiently represents the bitarray object (including
1041
+ its bit-endianness) and is guaranteed not to change in future releases.
1042
+
1043
+ See also: `Bitarray representations <https://github.com/ilanschnell/bitarray/blob/master/doc/represent.rst>`__
1044
+
1045
+ New in version 1.8
1046
+
1047
+
1048
+ ``strip(bitarray, /, mode='right')`` -> bitarray
1049
+ Return a new bitarray with zeros stripped from left, right or both ends.
1050
+ Allowed values for mode are the strings: ``left``, ``right``, ``both``
1051
+
1052
+
1053
+ ``subset(a, b, /)`` -> bool
1054
+ Return ``True`` if bitarray ``a`` is a subset of bitarray ``b``.
1055
+ ``subset(a, b)`` is equivalent to ``a | b == b`` (and equally ``a & b == a``) but
1056
+ more efficient as no intermediate bitarray object is created and the buffer
1057
+ iteration is stopped as soon as one mismatch is found.
1058
+
1059
+
1060
+ ``sum_indices(a, /, mode=1)`` -> int
1061
+ Return sum of indices of all active bits in bitarray ``a``.
1062
+ Equivalent to ``sum(i for i, v in enumerate(a) if v)``.
1063
+ ``mode=2`` sums square of indices.
1064
+
1065
+ New in version 3.6
1066
+
1067
+ New in version 3.7: add optional mode argument
1068
+
1069
+
1070
+ ``urandom(n, /, endian=None)`` -> bitarray
1071
+ Return random bitarray of length ``n`` (uses ``os.urandom()``).
1072
+
1073
+ New in version 1.7
1074
+
1075
+
1076
+ ``vl_decode(stream, /, endian=None)`` -> bitarray
1077
+ Decode binary stream (an integer iterator, or bytes-like object), and
1078
+ return the decoded bitarray. This function consumes only one bitarray and
1079
+ leaves the remaining stream untouched. Use ``vl_encode()`` for encoding.
1080
+
1081
+ See also: `Variable length bitarray format <https://github.com/ilanschnell/bitarray/blob/master/doc/variable_length.rst>`__, `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
1082
+
1083
+ New in version 2.2
1084
+
1085
+
1086
+ ``vl_encode(bitarray, /)`` -> bytes
1087
+ Return variable length binary representation of bitarray.
1088
+ This representation is useful for efficiently storing small bitarray
1089
+ in a binary stream. Use ``vl_decode()`` for decoding.
1090
+
1091
+ See also: `Variable length bitarray format <https://github.com/ilanschnell/bitarray/blob/master/doc/variable_length.rst>`__, `Comparison of bitarray codecs <https://github.com/ilanschnell/bitarray/blob/master/doc/codecs.rst>`__
1092
+
1093
+ New in version 2.2
1094
+
1095
+
1096
+ ``xor_indices(a, /)`` -> int
1097
+ Return xor reduced indices of all active bits in bitarray ``a``.
1098
+ This is essentially equivalent to
1099
+ ``reduce(operator.xor, (i for i, v in enumerate(a) if v))``.
1100
+
1101
+ New in version 3.2
1102
+
1103
+
1104
+ ``zeros(n, /, endian=None)`` -> bitarray
1105
+ Create a bitarray of length ``n``, with all values ``0``, and optional
1106
+ bit-endianness (``little`` or ``big``).
1107
+
1108
+
1109
+ The `bitarray.bitfields` module:
1110
+ --------------------------------
1111
+
1112
+ This sub-module was added in version 3.12.
1113
+ For a detailed description, see: `Bit-field structures <https://github.com/ilanschnell/bitarray/blob/master/doc/bitfields.rst>`__
1114
+
1115
+ ``Struct(format)`` -> compiled struct object
1116
+ Central class for packing and unpacking bit-level structures.
1117
+
1118
+
1119
+ ``calcsize(format)`` -> int
1120
+ Return the size (in bits) of the struct corresponding to the format string.
1121
+
1122
+
1123
+ ``compile(format)`` -> Struct
1124
+ Compile given format string and return a compiled format object that
1125
+ can be used to pack and/or unpack data multiple times.
1126
+
1127
+
1128
+ ``pack(format, v1, v2, ...)`` -> bitarray
1129
+ Return a bitarray containing the values v1, v2, ... packed according
1130
+ to the format string.
1131
+
1132
+
1133
+ ``pack_into(format, bitarray, offset, v1, v2, ...)`` -> None
1134
+ Pack the values v1, v2, ... into the writable bitarray starting at bit
1135
+ offset ``offset``. A negative offset counts from the end of bitarray.
1136
+
1137
+
1138
+ ``unpack(format, bitarray)`` -> tuple
1139
+ Return a tuple containing values unpacked according to the format string.
1140
+
1141
+
1142
+ ``unpack_from(format, bitarray, offset=0)`` -> tuple
1143
+ Unpack values from bitarray starting at bit offset ``offset``, and return a
1144
+ tuple. A negative offset counts from the end of bitarray.
1145
+
1146
+
1147
+ Struct methods:
1148
+ ^^^^^^^^^^^^^^^
1149
+
1150
+ ``format()`` -> str
1151
+ Return the canonical format string reconstructed from this compiled format.
1152
+
1153
+
1154
+ ``pack(v1, v2, ...)`` -> bitarray
1155
+ Return a bitarray containing the values v1, v2, ... packed according to this
1156
+ compiled format.
1157
+
1158
+
1159
+ ``pack_into(bitarray, offset, v1, v2, ...)`` -> None
1160
+ Pack the values v1, v2, ... into the writable bitarray starting at bit
1161
+ offset ``offset``. A negative offset counts from the end of bitarray.
1162
+
1163
+
1164
+ ``unpack(bitarray)`` -> tuple
1165
+ Return a tuple containing values unpacked according to this compiled format.
1166
+
1167
+
1168
+ ``unpack_from(bitarray, offset=0)`` -> tuple
1169
+ Unpack values from bitarray starting at bit offset ``offset``, and return a
1170
+ tuple. A negative offset counts from the end of bitarray.
1171
+
1172
+
1173
+ Struct attributes:
1174
+ ^^^^^^^^^^^^^^^^^^
1175
+
1176
+ ``width`` -> int
1177
+ Total number of bits in the compiled structure.
1178
+
1179
+ ``values`` -> int
1180
+ Number of values consumed by ``pack()`` and returned by ``unpack()``.