{"id":37084715,"url":"https://github.com/ph4r05/bitarray","last_synced_at":"2026-01-14T10:23:53.573Z","repository":{"id":57415337,"uuid":"76751745","full_name":"ph4r05/bitarray","owner":"ph4r05","description":"Efficient bit array operations library for Python implemented in C","archived":false,"fork":true,"pushed_at":"2021-06-08T16:03:07.000Z","size":2007,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-03T16:08:46.626Z","etag":null,"topics":["bit-manipulation","bitarray","cryptography","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"ilanschnell/bitarray","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ph4r05.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGE_LOG","contributing":"contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-17T22:50:49.000Z","updated_at":"2021-06-08T16:03:23.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ph4r05/bitarray","commit_stats":null,"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"purl":"pkg:github/ph4r05/bitarray","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph4r05%2Fbitarray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph4r05%2Fbitarray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph4r05%2Fbitarray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph4r05%2Fbitarray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ph4r05","download_url":"https://codeload.github.com/ph4r05/bitarray/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph4r05%2Fbitarray/sbom","scorecard":{"id":730358,"data":{"date":"2025-08-11","repo":{"name":"github.com/ph4r05/bitarray","commit":"b344e5a67365ca26b4b48d451c8bc1babaf3e853"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-22T14:13:57.135Z","repository_id":57415337,"created_at":"2025-08-22T14:13:57.135Z","updated_at":"2025-08-22T14:13:57.135Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28417032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:18:03.274Z","status":"ssl_error","status_checked_at":"2026-01-14T10:16:11.865Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bit-manipulation","bitarray","cryptography","python"],"created_at":"2026-01-14T10:23:52.750Z","updated_at":"2026-01-14T10:23:53.543Z","avatar_url":"https://github.com/ph4r05.png","language":"Python","readme":"bitarray: efficient arrays of booleans\n======================================\n\nThis library provides an object type which efficiently represents an array\nof booleans.  Bitarrays are sequence types and behave very much like usual\nlists.  Eight bits are represented by one byte in a contiguous block of\nmemory.  The user can select between two representations: little-endian\nand big-endian.  All of the functionality is implemented in C.\nMethods for accessing the machine representation are provided.\nThis can be useful when bit level access to binary files is required,\nsuch as portable bitmap image files (.pbm).  Also, when dealing with\ncompressed data which uses variable bit length encoding, you may find\nthis module useful.\n\n\nKey features\n------------\n\n* All functionality implemented in C.\n* Bitarray objects behave very much like a list object, in particular\n  slicing (including slice assignment and deletion) is supported.\n* The bit endianness can be specified for each bitarray object, see below.\n* Fast methods for encoding and decoding variable bit length prefix codes\n* Bitwise operations: ``~``, ``\u0026``, ``|``, ``^``, ``\u003c\u003c``, ``\u003e\u003e`` (as well as\n  their in-place versions ``\u0026=``, ``|=``, ``^=``, ``\u003c\u003c=``, ``\u003e\u003e=``).\n* Sequential search\n* Packing and unpacking to other binary data formats, e.g. ``numpy.ndarray``.\n* Pickling and unpickling of bitarray objects.\n* Bitarray objects support the buffer protocol\n* ``frozenbitarray`` objects which are hashable\n* Extensive test suite with over 300 unittests\n* Utility module ``bitarray.util``:\n\n  * conversion to hexadecimal string\n  * serialization\n  * pretty printing\n  * conversion to integers\n  * creating Huffman codes\n  * various count functions\n  * other helpful functions\n\n\nInstallation\n------------\n\nIf you have a working C compiler, you can simply:\n\n.. code-block:: shell-session\n\n    $ pip install bitarray\n\nIf you rather want to use precompiled binaries, you can:\n\n* ``conda install bitarray`` (both the default Anaconda repository as well\n  as conda-forge support bitarray)\n* download Windows wheels from\n  `Chris Gohlke \u003chttps://www.lfd.uci.edu/~gohlke/pythonlibs/#bitarray\u003e`__\n\nOnce you have installed the package, you may want to test it:\n\n.. code-block:: shell-session\n\n    $ python -c 'import bitarray; bitarray.test()'\n    bitarray is installed in: /Users/ilan/bitarray/bitarray\n    bitarray version: 2.1.0\n    sys.version: 2.7.15 (default, Mar  5 2020, 14:58:04) [GCC Clang 9.0.1]\n    sys.prefix: /Users/ilan/Mini3/envs/py27\n    pointer size: 64 bit\n    .........................................................................\n    .........................................................................\n    .............................................................\n    ----------------------------------------------------------------------\n    Ran 339 tests in 0.329s\n\n    OK\n\nYou can always import the function test,\nand ``test().wasSuccessful()`` will return ``True`` when the test went well.\n\n\nUsing the module\n----------------\n\nAs mentioned above, bitarray objects behave very much like lists, so\nthere is not too much to learn.  The biggest difference from list\nobjects (except that bitarray are obviously homogeneous) is the ability\nto access the machine representation of the object.\nWhen doing so, the bit endianness is of importance; this issue is\nexplained in detail in the section below.  Here, we demonstrate the\nbasic usage of bitarray objects:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from bitarray import bitarray\n    \u003e\u003e\u003e a = bitarray()         # create empty bitarray\n    \u003e\u003e\u003e a.append(1)\n    \u003e\u003e\u003e a.extend([1, 0])\n    \u003e\u003e\u003e a\n    bitarray('110')\n    \u003e\u003e\u003e x = bitarray(2 ** 20)  # bitarray of length 1048576 (uninitialized)\n    \u003e\u003e\u003e bitarray('1001 011')   # initialize from string (whitespace is ignored)\n    bitarray('1001011')\n    \u003e\u003e\u003e lst = [1, 0, False, True, True]\n    \u003e\u003e\u003e a = bitarray(lst)      # initialize from iterable\n    \u003e\u003e\u003e a\n    bitarray('10011')\n    \u003e\u003e\u003e a.count(1)\n    3\n    \u003e\u003e\u003e a.remove(0)            # removes first occurrence of 0\n    \u003e\u003e\u003e a\n    bitarray('1011')\n\nLike lists, bitarray objects support slice assignment and deletion:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e a = bitarray(50)\n    \u003e\u003e\u003e a.setall(0)            # set all elements in a to 0\n    \u003e\u003e\u003e a[11:37:3] = 9 * bitarray('1')\n    \u003e\u003e\u003e a\n    bitarray('00000000000100100100100100100100100100000000000000')\n    \u003e\u003e\u003e del a[12::3]\n    \u003e\u003e\u003e a\n    bitarray('0000000000010101010101010101000000000')\n    \u003e\u003e\u003e a[-6:] = bitarray('10011')\n    \u003e\u003e\u003e a\n    bitarray('000000000001010101010101010100010011')\n    \u003e\u003e\u003e a += bitarray('000111')\n    \u003e\u003e\u003e a[9:]\n    bitarray('001010101010101010100010011000111')\n\nIn addition, slices can be assigned to booleans, which is easier (and\nfaster) than assigning to a bitarray in which all values are the same:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e a = 20 * bitarray('0')\n    \u003e\u003e\u003e a[1:15:3] = True\n    \u003e\u003e\u003e a\n    bitarray('01001001001001000000')\n\nThis is easier and faster than:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e a = 20 * bitarray('0')\n    \u003e\u003e\u003e a[1:15:3] = 5 * bitarray('1')\n    \u003e\u003e\u003e a\n    bitarray('01001001001001000000')\n\nNote that in the latter we have to create a temporary bitarray whose length\nmust be known or calculated.  Another example of assigning slices to Booleans,\nis setting ranges:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e a = bitarray(30)\n    \u003e\u003e\u003e a[:] = 0         # set all elements to 0 - equivalent to a.setall(0)\n    \u003e\u003e\u003e a[10:25] = 1     # set elements in range(10, 25) to 1\n    \u003e\u003e\u003e a\n    bitarray('000000000011111111111111100000')\n\n\nBitwise operators\n-----------------\n\nBitarray objects support the bitwise operators ``~``, ``\u0026``, ``|``, ``^``,\n``\u003c\u003c``, ``\u003e\u003e`` (as well as their in-place versions ``\u0026=``, ``|=``, ``^=``,\n``\u003c\u003c=``, ``\u003e\u003e=``).  The behavior is very much what one would expect:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e a = bitarray('101110001')\n    \u003e\u003e\u003e ~a  # invert\n    bitarray('010001110')\n    \u003e\u003e\u003e b = bitarray('111001011')\n    \u003e\u003e\u003e a ^ b\n    bitarray('010111010')\n    \u003e\u003e\u003e a \u0026= b\n    \u003e\u003e\u003e a\n    bitarray('101000001')\n    \u003e\u003e\u003e a \u003c\u003c= 2\n    \u003e\u003e\u003e a\n    bitarray('100000100')\n    \u003e\u003e\u003e b \u003e\u003e 1\n    bitarray('011100101')\n\nThe C language does not specify the behavior of negative shifts and\nof left shifts larger or equal than the width of the promoted left operand.\nThe exact behavior is compiler/machine specific.\nThis Python bitarray library specifies the behavior as follows:\n\n* the length of the bitarray is never changed by any shift operation\n* blanks are filled by 0\n* negative shifts raise ``ValueError``\n* shifts larger or equal to the length of the bitarray result in\n  bitarrays with all values 0\n\n\nBit endianness\n--------------\n\nUnless explicitly converting to machine representation, using\nthe ``.tobytes()``, ``.frombytes()``, ``.tofile()`` and ``.fromfile()``\nmethods, as well as using ``memoryview``, the bit endianness will have no\neffect on any computation, and one can skip this section.\n\nSince bitarrays allows addressing individual bits, where the machine\nrepresents 8 bits in one byte, there are two obvious choices for this\nmapping: little-endian and big-endian.\n\nWhen dealing with the machine representation of bitarray objects, it is\nrecommended to always explicitly specify the endianness.\n\nBy default, bitarrays use big-endian representation:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e a = bitarray()\n    \u003e\u003e\u003e a.endian()\n    'big'\n    \u003e\u003e\u003e a.frombytes(b'A')\n    \u003e\u003e\u003e a\n    bitarray('01000001')\n    \u003e\u003e\u003e a[6] = 1\n    \u003e\u003e\u003e a.tobytes()\n    b'C'\n\nBig-endian means that the most-significant bit comes first.\nHere, ``a[0]`` is the lowest address (index) and most significant bit,\nand ``a[7]`` is the highest address and least significant bit.\n\nWhen creating a new bitarray object, the endianness can always be\nspecified explicitly:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e a = bitarray(endian='little')\n    \u003e\u003e\u003e a.frombytes(b'A')\n    \u003e\u003e\u003e a\n    bitarray('10000010')\n    \u003e\u003e\u003e a.endian()\n    'little'\n\nHere, the low-bit comes first because little-endian means that increasing\nnumeric significance corresponds to an increasing address.\nSo ``a[0]`` is the lowest address and least significant bit,\nand ``a[7]`` is the highest address and most significant bit.\n\nThe bit endianness is a property of the bitarray object.\nThe endianness cannot be changed once a bitarray object is created.\nWhen comparing bitarray objects, the endianness (and hence the machine\nrepresentation) is irrelevant; what matters is the mapping from indices\nto bits:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e bitarray('11001', endian='big') == bitarray('11001', endian='little')\n    True\n\nBitwise operations (``|``, ``^``, ``\u0026=``, ``|=``, ``^=``, ``~``) are\nimplemented efficiently using the corresponding byte operations in C, i.e. the\noperators act on the machine representation of the bitarray objects.\nTherefore, it is not possible to perform bitwise operators on bitarrays\nwith different endianness.\n\nWhen converting to and from machine representation, using\nthe ``.tobytes()``, ``.frombytes()``, ``.tofile()`` and ``.fromfile()``\nmethods, the endianness matters:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e a = bitarray(endian='little')\n    \u003e\u003e\u003e a.frombytes(b'\\x01')\n    \u003e\u003e\u003e a\n    bitarray('10000000')\n    \u003e\u003e\u003e b = bitarray(endian='big')\n    \u003e\u003e\u003e b.frombytes(b'\\x80')\n    \u003e\u003e\u003e b\n    bitarray('10000000')\n    \u003e\u003e\u003e a == b\n    True\n    \u003e\u003e\u003e a.tobytes() == b.tobytes()\n    False\n\nAs mentioned above, the endianness can not be changed once an object is\ncreated.  However, you can create a new bitarray with different endianness:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e a = bitarray('111000', endian='little')\n    \u003e\u003e\u003e b = bitarray(a, endian='big')\n    \u003e\u003e\u003e b\n    bitarray('111000')\n    \u003e\u003e\u003e a == b\n    True\n\n\nBuffer protocol\n---------------\n\nPython 2.7 provides memoryview objects, which allow Python code to access\nthe internal data of an object that supports the buffer protocol without\ncopying.  Bitarray objects support this protocol, with the memory being\ninterpreted as simple bytes:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e a = bitarray('01000001 01000010 01000011', endian='big')\n    \u003e\u003e\u003e v = memoryview(a)\n    \u003e\u003e\u003e len(v)\n    3\n    \u003e\u003e\u003e v[-1]\n    67\n    \u003e\u003e\u003e v[:2].tobytes()\n    b'AB'\n    \u003e\u003e\u003e v.readonly  # changing a bitarray's memory is also possible\n    False\n    \u003e\u003e\u003e v[1] = 111\n    \u003e\u003e\u003e a\n    bitarray('010000010110111101000011')\n\n\nVariable bit length prefix codes\n--------------------------------\n\nThe ``.encode()`` method takes a dictionary mapping symbols to bitarrays\nand an iterable, and extends the bitarray object with the encoded symbols\nfound while iterating.  For example:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e d = {'H':bitarray('111'), 'e':bitarray('0'),\n    ...      'l':bitarray('110'), 'o':bitarray('10')}\n    ...\n    \u003e\u003e\u003e a = bitarray()\n    \u003e\u003e\u003e a.encode(d, 'Hello')\n    \u003e\u003e\u003e a\n    bitarray('111011011010')\n\nNote that the string ``'Hello'`` is an iterable, but the symbols are not\nlimited to characters, in fact any immutable Python object can be a symbol.\nTaking the same dictionary, we can apply the ``.decode()`` method which will\nreturn a list of the symbols:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e a.decode(d)\n    ['H', 'e', 'l', 'l', 'o']\n    \u003e\u003e\u003e ''.join(a.decode(d))\n    'Hello'\n\nSince symbols are not limited to being characters, it is necessary to return\nthem as elements of a list, rather than simply returning the joined string.\nThe above dictionary ``d`` can be efficiently constructed using the function\n``bitarray.util.huffman_code()``.  I also wrote `Huffman coding in Python\nusing bitarray \u003chttp://ilan.schnell-web.net/prog/huffman/\u003e`__ for more\nbackground information.\n\nWhen the codes are large, and you have many decode calls, most time will\nbe spent creating the (same) internal decode tree objects.  In this case,\nit will be much faster to create a ``decodetree`` object, which can be\npassed to bitarray's ``.decode()`` and ``.iterdecode()`` methods, instead\nof passing the prefix code dictionary to those methods itself:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from bitarray import bitarray, decodetree\n    \u003e\u003e\u003e t = decodetree({'a': bitarray('0'), 'b': bitarray('1')})\n    \u003e\u003e\u003e a = bitarray('0110')\n    \u003e\u003e\u003e a.decode(t)\n    ['a', 'b', 'b', 'a']\n    \u003e\u003e\u003e ''.join(a.iterdecode(t))\n    'abba'\n\nThe ``decodetree`` object is immutable and unhashable, and it's sole purpose\nis to be passed to bitarray's `.decode()` and `.iterdecode()` methods.\n\n\nFrozenbitarrays\n---------------\n\nA ``frozenbitarray`` object is very similar to the bitarray object.\nThe difference is that this a ``frozenbitarray`` is immutable, and hashable,\nand can therefore be used as a dictionary key:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from bitarray import frozenbitarray\n    \u003e\u003e\u003e key = frozenbitarray('1100011')\n    \u003e\u003e\u003e {key: 'some value'}\n    {frozenbitarray('1100011'): 'some value'}\n    \u003e\u003e\u003e key[3] = 1\n    Traceback (most recent call last):\n      File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n      File \"bitarray/__init__.py\", line 41, in __delitem__\n        raise TypeError(\"'frozenbitarray' is immutable\")\n    TypeError: 'frozenbitarray' is immutable\n\n\nReference\n=========\n\nbitarray version: 2.1.0 -- `change log \u003chttps://github.com/ilanschnell/bitarray/blob/master/doc/changelog.rst\u003e`__\n\nIn the following, ``item`` and ``value`` are usually a single bit -\nan integer 0 or 1.\n\n\nThe bitarray object:\n--------------------\n\n``bitarray(initializer=0, /, endian='big')`` -\u003e bitarray\n   Return a new bitarray object whose items are bits initialized from\n   the optional initial object, and endianness.\n   The initializer may be of the following types:\n\n   ``int``: Create a bitarray of given integer length.  The initial values are\n   uninitialized.\n\n   ``str``: Create bitarray from a string of ``0`` and ``1``.\n\n   ``iterable``: Create bitarray from iterable or sequence or integers 0 or 1.\n\n   The optional keyword arguments ``endian`` specifies the bit endianness of the\n   created bitarray object.\n   Allowed values are the strings ``big`` and ``little`` (default is ``big``).\n   The bit endianness only effects the when buffer representation of the\n   bitarray.\n\n\n**A bitarray object supports the following methods:**\n\n``all()`` -\u003e bool\n   Return True when all bits in the array are True.\n   Note that ``a.all()`` is faster than ``all(a)``.\n\n\n``any()`` -\u003e bool\n   Return True when any bit in the array is True.\n   Note that ``a.any()`` is faster than ``any(a)``.\n\n\n``append(item, /)``\n   Append ``item`` to the end of the bitarray.\n\n\n``buffer_info()`` -\u003e tuple\n   Return a tuple (address, size, endianness, unused, allocated) giving the\n   memory address of the bitarray's buffer, the buffer size (in bytes),\n   the bit endianness as a string, the number of unused bits within the last\n   byte, and the allocated memory for the buffer (in bytes).\n\n\n``bytereverse()``\n   For all bytes representing the bitarray, reverse the bit order (in-place).\n   Note: This method changes the actual machine values representing the\n   bitarray; it does *not* change the endianness of the bitarray object.\n\n\n``clear()``\n   Remove all items from the bitarray.\n\n\n``copy()`` -\u003e bitarray\n   Return a copy of the bitarray.\n\n\n``count(value=1, start=0, stop=\u003cend of array\u003e, /)`` -\u003e int\n   Count the number of occurrences of ``value`` in the bitarray.\n\n\n``decode(code, /)`` -\u003e list\n   Given a prefix code (a dict mapping symbols to bitarrays, or ``decodetree``\n   object), decode the content of the bitarray and return it as a list of\n   symbols.\n\n\n``encode(code, iterable, /)``\n   Given a prefix code (a dict mapping symbols to bitarrays),\n   iterate over the iterable object with symbols, and extend the bitarray\n   with the corresponding bitarray for each symbol.\n\n\n``endian()`` -\u003e str\n   Return the bit endianness of the bitarray as a string (``little`` or ``big``).\n\n\n``extend(iterable, /)``\n   Append all the items from ``iterable`` to the end of the bitarray.\n   If the iterable is a string, each ``0`` and ``1`` are appended as\n   bits (ignoring whitespace).\n\n\n``fill()`` -\u003e int\n   Add zeros to the end of the bitarray, such that the length of the bitarray\n   will be a multiple of 8, and return the number of bits added (0..7).\n\n\n``find(sub_bitarray, start=0, stop=\u003cend of array\u003e, /)`` -\u003e int\n   Return the lowest index where sub_bitarray is found, such that sub_bitarray\n   is contained within ``[start:stop]``.\n   Return -1 when sub_bitarray is not found.\n\n\n``frombytes(bytes, /)``\n   Extend bitarray with raw bytes.  That is, each append byte will add eight\n   bits to the bitarray.\n\n\n``fromfile(f, n=-1, /)``\n   Extend bitarray with up to n bytes read from the file object f.\n   When n is omitted or negative, reads all data until EOF.\n   When n is provided and positive but exceeds the data available,\n   ``EOFError`` is raised (but the available data is still read and appended.\n\n\n``index(sub_bitarray, start=0, stop=\u003cend of array\u003e, /)`` -\u003e int\n   Return the lowest index where sub_bitarray is found, such that sub_bitarray\n   is contained within ``[start:stop]``.\n   Raises ``ValueError`` when the sub_bitarray is not present.\n\n\n``insert(index, value, /)``\n   Insert ``value`` into the bitarray before ``index``.\n\n\n``invert(index=\u003call bits\u003e, /)``\n   Invert all bits in the array (in-place).\n   When the optional ``index`` is given, only invert the single bit at index.\n\n\n``iterdecode(code, /)`` -\u003e iterator\n   Given a prefix code (a dict mapping symbols to bitarrays, or ``decodetree``\n   object), decode the content of the bitarray and return an iterator over\n   the symbols.\n\n\n``itersearch(sub_bitarray, /)`` -\u003e iterator\n   Searches for the given sub_bitarray in self, and return an iterator over\n   the start positions where bitarray matches self.\n\n\n``pack(bytes, /)``\n   Extend the bitarray from bytes, where each byte corresponds to a single\n   bit.  The byte ``b'\\x00'`` maps to bit 0 and all other characters map to\n   bit 1.\n   This method, as well as the unpack method, are meant for efficient\n   transfer of data between bitarray objects to other python objects\n   (for example NumPy's ndarray object) which have a different memory view.\n\n\n``pop(index=-1, /)`` -\u003e item\n   Return the i-th (default last) element and delete it from the bitarray.\n   Raises ``IndexError`` if bitarray is empty or index is out of range.\n\n\n``remove(value, /)``\n   Remove the first occurrence of ``value`` in the bitarray.\n   Raises ``ValueError`` if item is not present.\n\n\n``reverse()``\n   Reverse the order of bits in the array (in-place).\n\n\n``search(sub_bitarray, limit=\u003cnone\u003e, /)`` -\u003e list\n   Searches for the given sub_bitarray in self, and return the list of start\n   positions.\n   The optional argument limits the number of search results to the integer\n   specified.  By default, all search results are returned.\n\n\n``setall(value, /)``\n   Set all elements in the bitarray to ``value``.\n   Note that ``a.setall(value)`` is equivalent to ``a[:] = value``.\n\n\n``sort(reverse=False)``\n   Sort the bits in the array (in-place).\n\n\n``to01()`` -\u003e str\n   Return a string containing '0's and '1's, representing the bits in the\n   bitarray object.\n\n\n``tobytes()`` -\u003e bytes\n   Return the byte representation of the bitarray.\n   When the length of the bitarray is not a multiple of 8, the few remaining\n   bits are considered 0.\n\n\n``tofile(f, /)``\n   Write the byte representation of the bitarray to the file object f.\n   When the length of the bitarray is not a multiple of 8, the few remaining\n   bits are considered 0.\n\n\n``tolist()`` -\u003e list\n   Return a list with the items (0 or 1) in the bitarray.\n   Note that the list object being created will require 32 or 64 times more\n   memory (depending on the machine architecture) than the bitarray object,\n   which may cause a memory error if the bitarray is very large.\n\n\n``unpack(zero=b'\\x00', one=b'\\x01')`` -\u003e bytes\n   Return bytes containing one character for each bit in the bitarray,\n   using the specified mapping.\n\n\nOther objects:\n--------------\n\n``frozenbitarray(initializer=0, /, endian='big')`` -\u003e frozenbitarray\n   Return a frozenbitarray object, which is initialized the same way a bitarray\n   object is initialized.  A frozenbitarray is immutable and hashable.\n   Its contents cannot be altered after it is created; however, it can be used\n   as a dictionary key.\n\n\n``decodetree(code, /)`` -\u003e decodetree\n   Given a prefix code (a dict mapping symbols to bitarrays),\n   create a binary tree object to be passed to ``.decode()`` or ``.iterdecode()``.\n\n\nFunctions defined in the `bitarray` module:\n-------------------------------------------\n\n``bits2bytes(n, /)`` -\u003e int\n   Return the number of bytes necessary to store n bits.\n\n\n``get_default_endian()`` -\u003e string\n   Return the default endianness for new bitarray objects being created.\n   Under normal circumstances, the return value is ``big``.\n\n\n``test(verbosity=1, repeat=1)`` -\u003e TextTestResult\n   Run self-test, and return unittest.runner.TextTestResult object.\n\n\nFunctions defined in `bitarray.util` module:\n--------------------------------------------\n\n``zeros(length, /, endian=None)`` -\u003e bitarray\n   Create a bitarray of length, with all values 0, and optional\n   endianness, which may be 'big', 'little'.\n\n\n``urandom(length, /, endian=None)`` -\u003e bitarray\n   Return a bitarray of ``length`` random bits (uses ``os.urandom``).\n\n\n``pprint(bitarray, /, stream=None, group=8, indent=4, width=80)``\n   Prints the formatted representation of object on ``stream``, followed by a\n   newline.  If ``stream`` is ``None``, ``sys.stdout`` is used.  By default, elements\n   are grouped in bytes (8 elements), and 8 bytes (64 elements) per line.\n   Non-bitarray objects are printed by the standard library\n   function ``pprint.pprint()``.\n\n\n``make_endian(bitarray, endian, /)`` -\u003e bitarray\n   When the endianness of the given bitarray is different from ``endian``,\n   return a new bitarray, with endianness ``endian`` and the same elements\n   as the original bitarray.\n   Otherwise (endianness is already ``endian``) the original bitarray is returned\n   unchanged.\n\n\n``rindex(bitarray, value=1, /)`` -\u003e int\n   Return the rightmost index of ``value`` in bitarray.\n   Raises ``ValueError`` if the value is not present.\n\n\n``strip(bitarray, mode='right', /)`` -\u003e bitarray\n   Return a new bitarray with zeros stripped from left, right or both ends.\n   Allowed values for mode are the strings: ``left``, ``right``, ``both``\n\n\n``count_n(a, n, /)`` -\u003e int\n   Return the smallest index ``i`` for which ``a[:i].count() == n``.\n   Raises ``ValueError``, when n exceeds total count (``a.count()``).\n\n\n``parity(a, /)`` -\u003e int\n   Return the parity of bitarray ``a``.\n   This is equivalent to ``a.count() % 2`` (but more efficient).\n\n\n``count_and(a, b, /)`` -\u003e int\n   Return ``(a \u0026 b).count()`` in a memory efficient manner,\n   as no intermediate bitarray object gets created.\n\n\n``count_or(a, b, /)`` -\u003e int\n   Return ``(a | b).count()`` in a memory efficient manner,\n   as no intermediate bitarray object gets created.\n\n\n``count_xor(a, b, /)`` -\u003e int\n   Return ``(a ^ b).count()`` in a memory efficient manner,\n   as no intermediate bitarray object gets created.\n\n\n``subset(a, b, /)`` -\u003e bool\n   Return ``True`` if bitarray ``a`` is a subset of bitarray ``b``.\n   ``subset(a, b)`` is equivalent to ``(a \u0026 b).count() == a.count()`` but is more\n   efficient since we can stop as soon as one mismatch is found, and no\n   intermediate bitarray object gets created.\n\n\n``ba2hex(bitarray, /)`` -\u003e hexstr\n   Return a string containing the hexadecimal representation of\n   the bitarray (which has to be multiple of 4 in length).\n\n\n``hex2ba(hexstr, /, endian=None)`` -\u003e bitarray\n   Bitarray of hexadecimal representation.  hexstr may contain any number\n   (including odd numbers) of hex digits (upper or lower case).\n\n\n``ba2base(n, bitarray, /)`` -\u003e str\n   Return a string containing the base ``n`` ASCII representation of\n   the bitarray.  Allowed values for ``n`` are 2, 4, 8, 16, 32 and 64.\n   The bitarray has to be multiple of length 1, 2, 3, 4, 5 or 6 respectively.\n   For ``n=16`` (hexadecimal), ``ba2hex()`` will be much faster, as ``ba2base()``\n   does not take advantage of byte level operations.\n   For ``n=32`` the RFC 4648 Base32 alphabet is used, and for ``n=64`` the\n   standard base 64 alphabet is used.\n\n\n``base2ba(n, asciistr, /, endian=None)`` -\u003e bitarray\n   Bitarray of the base ``n`` ASCII representation.\n   Allowed values for ``n`` are 2, 4, 8, 16 and 32.\n   For ``n=16`` (hexadecimal), ``hex2ba()`` will be much faster, as ``base2ba()``\n   does not take advantage of byte level operations.\n   For ``n=32`` the RFC 4648 Base32 alphabet is used, and for ``n=64`` the\n   standard base 64 alphabet is used.\n\n\n``ba2int(bitarray, /, signed=False)`` -\u003e int\n   Convert the given bitarray into an integer.\n   The bit-endianness of the bitarray is respected.\n   ``signed`` indicates whether two's complement is used to represent the integer.\n\n\n``int2ba(int, /, length=None, endian=None, signed=False)`` -\u003e bitarray\n   Convert the given integer to a bitarray (with given endianness,\n   and no leading (big-endian) / trailing (little-endian) zeros), unless\n   the ``length`` of the bitarray is provided.  An ``OverflowError`` is raised\n   if the integer is not representable with the given number of bits.\n   ``signed`` determines whether two's complement is used to represent the integer,\n   and requires ``length`` to be provided.\n\n\n``serialize(bitarray, /)`` -\u003e bytes\n   Return a serialized representation of the bitarray, which may be passed to\n   ``deserialize()``.  It efficiently represents the bitarray object (including\n   its endianness) and is guaranteed not to change in future releases.\n\n\n``deserialize(bytes, /)`` -\u003e bitarray\n   Return a bitarray given the bytes representation returned by ``serialize()``.\n\n\n``huffman_code(dict, /, endian=None)`` -\u003e dict\n   Given a frequency map, a dictionary mapping symbols to their frequency,\n   calculate the Huffman code, i.e. a dict mapping those symbols to\n   bitarrays (with given endianness).  Note that the symbols are not limited\n   to being strings.  Symbols may may be any hashable object (such as ``None``).\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fph4r05%2Fbitarray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fph4r05%2Fbitarray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fph4r05%2Fbitarray/lists"}