{"id":27290761,"url":"https://github.com/hellman/binteger","last_synced_at":"2025-04-11T21:38:53.712Z","repository":{"id":63885341,"uuid":"296609383","full_name":"hellman/binteger","owner":"hellman","description":"Binary integer representation toolkit","archived":false,"fork":false,"pushed_at":"2023-10-26T14:37:17.000Z","size":117,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T11:05:52.468Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/hellman.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":"2020-09-18T12:04:29.000Z","updated_at":"2023-11-01T20:12:30.000Z","dependencies_parsed_at":"2023-01-23T17:30:49.470Z","dependency_job_id":null,"html_url":"https://github.com/hellman/binteger","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellman%2Fbinteger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellman%2Fbinteger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellman%2Fbinteger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellman%2Fbinteger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hellman","download_url":"https://codeload.github.com/hellman/binteger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248485368,"owners_count":21111841,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-04-11T21:38:52.951Z","updated_at":"2025-04-11T21:38:53.696Z","avatar_url":"https://github.com/hellman.png","language":"Python","readme":"# binteger\n\n`binteger` is a small toolkit for manipulating integers in their binary\n(fixed-width) representation (big endian - most significant bits go first).\n\nThis module is quite similar to [bitstring](https://github.com/scott-griffiths/bitstring) which is pretty awesome.\n\nThe difference is that the API is a bit more compact\nto aid simple conversions, such as:\n\n```py\n\u003e\u003e\u003e from binteger import Bin\n\u003e\u003e\u003e Bin(0x4142).bytes\nb'AB'\n\u003e\u003e\u003e Bin(b'AB').int == 0x4142\nTrue\n\u003e\u003e\u003e Bin(14, n=6).tuple\n(0, 0, 1, 1, 1, 0)\n\u003e\u003e\u003e Bin(0x123, n=16).rol(8).hex\n'2301'\n```\n\n## Installation\n\n```sh\npip install binteger\n```\n\n## Documentation\n\nSee [documentation](https://binteger.readthedocs.io/en/latest/).\n\n\n## Examples\n\nCreation:\n\n```py\n\u003e\u003e\u003e Bin(16).n\n5\n\u003e\u003e\u003e Bin(16).int\n16\n\u003e\u003e\u003e Bin(16, n=3)\nTraceback (most recent call last):\nValueError: integer out of range\n```\n\n```py\n\u003e\u003e\u003e Bin(b\"AB\")  # bytes are unpacked\nBin(0b0100000101000010, n=16)\n\u003e\u003e\u003e Bin(\"010\")  # strings must be the binary representation\nBin(0b010, n=3)\n\u003e\u003e\u003e Bin(\"AB\")  # strings must be 01-formed\nTraceback (most recent call last):\nValueError: invalid literal for int() with base 10: 'A'\n```\n\n```py\n\u003e\u003e\u003e Bin.empty(4)\nBin(0b0000, n=4)\n\u003e\u003e\u003e Bin.full(4)\nBin(0b1111, n=4)\n\u003e\u003e\u003e Bin.unit(1, 4)\nBin(0b0100, n=4)\n```\n\nOutputting (formatting):\n\n```py\n\u003e\u003e\u003e str(Bin(16))\n'10000'\n\u003e\u003e\u003e repr(Bin(16))\n'Bin(0b10000, n=5)'\n\u003e\u003e\u003e str(Bin(16, 8))\n'00010000'\n```\n\n```py\n\u003e\u003e\u003e Bin(16).tuple\n(1, 0, 0, 0, 0)\n\u003e\u003e\u003e Bin(16).list\n[1, 0, 0, 0, 0]\n\u003e\u003e\u003e Bin(0x4142).bytes\nb'AB'\n\u003e\u003e\u003e Bin(\"1101\").int\n13\n\u003e\u003e\u003e Bin(\"1110001101\").hex\n'38d'\n\u003e\u003e\u003e Bin(\"1101\") == Bin((1, 1, 0, 1)) == Bin([1, 1, 0, 1]) == Bin(13)\nTrue\n```\n\n```py\n\u003e\u003e\u003e Bin([0, 1, 2])\nTraceback (most recent call last):\nValueError: integer 2 is not binary\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellman%2Fbinteger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhellman%2Fbinteger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellman%2Fbinteger/lists"}