{"id":19313664,"url":"https://github.com/mingrammer/bit-counter","last_synced_at":"2025-07-12T07:33:13.775Z","repository":{"id":86183721,"uuid":"126844935","full_name":"mingrammer/bit-counter","owner":"mingrammer","description":":bulb: A simple bit counter","archived":false,"fork":false,"pushed_at":"2018-03-26T16:09:39.000Z","size":6,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-02T01:15:44.084Z","etag":null,"topics":["bit","counter"],"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/mingrammer.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-03-26T14:53:29.000Z","updated_at":"2022-11-28T20:26:45.000Z","dependencies_parsed_at":"2023-05-05T07:32:44.143Z","dependency_job_id":null,"html_url":"https://github.com/mingrammer/bit-counter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mingrammer/bit-counter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mingrammer%2Fbit-counter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mingrammer%2Fbit-counter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mingrammer%2Fbit-counter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mingrammer%2Fbit-counter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mingrammer","download_url":"https://codeload.github.com/mingrammer/bit-counter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mingrammer%2Fbit-counter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264958135,"owners_count":23689006,"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":["bit","counter"],"created_at":"2024-11-10T00:40:42.232Z","updated_at":"2025-07-12T07:33:13.770Z","avatar_url":"https://github.com/mingrammer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bit Counter\n\nA simple bit counter. There are 2 types of bit counter: increment and decrement. Bit counter idea was borrowed from digital bit counter. Each index of an array represents each bit of a bit sequence.\n\n## Run \u0026 Test\n\n```bash\n# 6 bit counter example\npython3 main.py\n\n# 8 bit counter tests\npython3 test.py\n```\n\n## Increment\n\nIncrement the bit count by 1. It inverts 1 to 0 until it encounters 0, and inverts 0 to 1 when it encounters 0.\n\n```\n00000000\n00000001\n00000010\n00000011\n00000100\n........\n```\n\n### How it works\n\n```\n000111\n     ^ (1 to 0)\n000110\n    ^ (1 to 0)\n000100\n   ^ (1 to 0)\n001000\n  ^ (0 to 1)\n```\n\n### Implementation\n\n```python\ndef increment(bits):\n    i = 0\n    m = len(bits) - 1\n    while i \u003c= m and bits[m-i] == 1:\n        bits[m-i] = 0\n        i += 1\n    # Index overflow prevention\n    if i \u003c= m:\n        bits[m-i] = 1\n```\n\n## Decrement\n\nDecrement the bit count by 1. It inverts 0 to 1 until it encounters 1, and inverts 1 to 0 when it encounters 1.\n\n```\n11111111\n11111110\n11111101\n11111100\n11111011\n........\n```\n\n### How it works\n\n```\n001000\n     ^ (0 to 1)\n001001\n    ^ (0 to 1)\n001011\n   ^ (0 to 1)\n000111\n  ^ (1 to 0)\n```\n\n### Implementation\n\n```python\ndef decrement(bits):\n    i = 0\n    m = len(bits) - 1\n    while i \u003c= m and bits[m-i] == 0:\n        bits[m-i] = 1\n        i += 1\n    # Index overflow prevention\n    if i \u003c= m:\n        bits[m-i] = 0\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmingrammer%2Fbit-counter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmingrammer%2Fbit-counter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmingrammer%2Fbit-counter/lists"}