{"id":34624423,"url":"https://github.com/vitalij555/bitops","last_synced_at":"2026-05-26T00:31:25.012Z","repository":{"id":62281752,"uuid":"557898533","full_name":"vitalij555/bitops","owner":"vitalij555","description":"Bit manipulation library","archived":false,"fork":false,"pushed_at":"2025-08-26T19:09:31.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-03T17:07:43.970Z","etag":null,"topics":["bit","bitwise-arithmetic","bitwise-operators","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vitalij555.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-26T14:09:02.000Z","updated_at":"2025-08-26T19:09:35.000Z","dependencies_parsed_at":"2023-01-22T19:30:16.077Z","dependency_job_id":null,"html_url":"https://github.com/vitalij555/bitops","commit_stats":null,"previous_names":["vitalij555/binary-operations"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vitalij555/bitops","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalij555%2Fbitops","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalij555%2Fbitops/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalij555%2Fbitops/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalij555%2Fbitops/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vitalij555","download_url":"https://codeload.github.com/vitalij555/bitops/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalij555%2Fbitops/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33498780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-25T14:31:05.219Z","status":"ssl_error","status_checked_at":"2026-05-25T14:31:02.878Z","response_time":57,"last_error":"SSL_read: 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","bitwise-arithmetic","bitwise-operators","python"],"created_at":"2025-12-24T15:45:14.852Z","updated_at":"2026-05-26T00:31:24.991Z","avatar_url":"https://github.com/vitalij555.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Upload Python Package](https://github.com/vitalij555/bitops/workflows/Upload%20Python%20Package/badge.svg)\r\n[![PyPi version](https://img.shields.io/pypi/v/bitops.svg?style=flat-square) ](https://pypi.python.org/pypi/bitops) [![Supported Python versions](https://img.shields.io/pypi/pyversions/bitops.svg?style=flat-square) ](https://pypi.org/project/bitops) [![License](https://img.shields.io/pypi/l/bitops.svg?style=flat-square) ](https://choosealicense.com/licenses) [![Downloads](https://pepy.tech/badge/bitops)](https://pepy.tech/project/bitops) [![codecov](https://codecov.io/gh/vitalij555/bitops/branch/master/graph/badge.svg)](https://codecov.io/gh/vitalij555/bitops)\r\n\r\n\r\n\r\n\r\n# bitops — Tiny Python bit manipulation helpers\r\n\r\nA lightweight set of utilities for common bit-twiddling tasks (get/set/clear bits, extract/set ranges, compute byte sizes), with **BIG** and **LITTLE** endianness support.\r\n\r\nWorks great as a foundation for parsers (e.g., BER-TLV, EMV) and binary protocols.\r\n\r\n---\r\n\r\n## Features\r\n\r\n- \\`ENDIANNESS\\` enum (\\`BIG\\`, \\`LITTLE\\`)\r\n- Bit queries: \\`get_bit\\`, \\`is_bit_set\\`\r\n- Bit mutation: \\`set_bit\\`, \\`clear_bit\\`\r\n- Ranged extraction \u0026 setting: \\`get_bit_range_as_int\\`, \\`set_bit_range_from_int\\`\r\n- Utility: \\`get_effective_length_in_bytes\\` (how many bytes to represent an int)\r\n\r\n---\r\n\r\n## Install\r\n\r\n```bash\r\npip install bitops\r\n```\r\n\r\n## Quick Start\r\n\r\n```python\r\nfrom bitops.BinaryOperations import (\r\n    ENDIANNESS,\r\n    get_bit, set_bit, clear_bit,\r\n    get_bit_range_as_int, set_bit_range_from_int,\r\n    get_effective_length_in_bytes\r\n)\r\n\r\n# Single-bit access (big-endian bit numbering)\r\nassert get_bit(0x0F, 2) == 1\r\nassert get_bit(0x0F, 7) == 0\r\n\r\n# Little-endian bit numbering\r\nassert get_bit(0x01, 7, endiannes=ENDIANNESS.LITTLE) == 1\r\n\r\n# Set / clear\r\nx = set_bit(0x00, 5)          # -\u003e 0b0010_0000\r\ny = clear_bit(0xFF, 7)        # -\u003e 0b0111_1111\r\n\r\n# Ranges: [start, end) half-open, bit 0 is LSB in big-endian numbering\r\nv = get_bit_range_as_int(0b1110_0101, 2, 5)  # -\u003e 0b101 = 5\r\n\r\n# Set a range: insert value's bits starting at position 'pos'\r\nz = set_bit_range_from_int(0x00, 2, 0b101)   # -\u003e 0b0001_0100 (0x14)\r\n\r\n# Byte width utility\r\nassert get_effective_length_in_bytes(0x00) == 1\r\nassert get_effective_length_in_bytes(0x1234) == 2\r\n```\r\n\r\n\r\n## API\r\n\r\n`ENDIANNESS`\r\n\r\n- `ENDIANNESS.BIG`: big-endian bit numbering in APIs (bit 0 is LSB, positions increment toward MSB).\r\n- `ENDIANNESS.LITTLE`: mirrored bit positions across the byte width of the value.\r\n\r\nNote: Functions take an integer `value`. For endianness handling, the code computes the width using `get_effective_length_in_bytes(value)`.\r\n\r\n`get_effective_length_in_bytes(value: int) -\u003e int`\r\n\r\nReturn minimal number of bytes required to represent `value`. Zero returns 1.\r\n\r\n`is_bit_set(value: int, n: int, endiannes=ENDIANNESS.BIG) -\u003e bool`\r\n\r\nReturn `True` if bit `n` is set under the specified endianness.\r\n\r\n`get_bit(value: int, n: int, endiannes=ENDIANNESS.BIG) -\u003e int`\r\n\r\nReturn the bit (0 or 1). Validates bounds and `None`.\r\n\r\n`set_bit(value: int, n: int, endiannes=ENDIANNESS.BIG) -\u003e int`\r\n\r\nReturn `value` with bit `n` set.\r\n\r\n`clear_bit(value: int, n: int, endiannes=ENDIANNESS.BIG) -\u003e int`\r\n\r\nReturn `value` with bit `n` cleared.\r\n\r\n`get_bit_range_as_int(value: int, start: int, end: int, endiannes=ENDIANNESS.BIG) -\u003e int`\r\n\r\nExtract bits [start, end) as an integer. Validates bounds; supports LITTLE endianness via mirrored positions.\r\n\r\n`set_bit_range_from_int(target_byte: int, pos: int, value: int, endiannes=ENDIANNESS.BIG) -\u003e int`\r\n\r\nInsert `value`’s bits into `target_byte` starting at bit position `pos` (honoring endianness).\r\nBounds are validated against the current byte-width of `target_byte`.\r\n\r\n\r\n## Endianness Notes\r\n\r\n- For `ENDIANNESS.BIG`, bit 0 is LSB; bit 7 is MSB (for a single byte). For multi-byte integers, bit positions continue upward.\r\n- For `ENDIANNESS.LITTLE`, functions mirror positions across the computed width of `value`. E.g., in an 8-bit value, querying bit 0 (BIG) corresponds to bit 7 (LITTLE).\r\n\r\n\r\n## Testing\r\n\r\nThis repo uses `pytest`.\r\n\r\n```python\r\npytest -v\r\n```\r\n\r\n\r\n## Error Handling\r\n\r\nAll APIs raise `ValueError` for:\r\n\r\n- `value` or positions being `None`\r\n- Bit indices out of current width for `value`\r\n- Unknown endianness\r\n\r\nSome parameter checks use `AssertionError` semantics (e.g., invalid ranges). You may later convert these to explicit `ValueError` for consistency.\r\n\r\n\r\n## Versioning \u0026 Compatibility\r\n\r\n- Python 3.8+\r\n- No external dependencies\r\n\r\n\r\n## Contributing\r\n\r\nIssues and PRs are welcome! Please:\r\n\r\n1. Open an issue to discuss larger changes\r\n2. Add tests for new behavior\r\n3. Run `pytest` locally before opening a PR\r\n\r\n\r\n\r\n## License\r\n\r\nMIT License — see `LICENSE`.\r\n\r\n\r\n\r\n\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitalij555%2Fbitops","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitalij555%2Fbitops","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitalij555%2Fbitops/lists"}