{"id":19267009,"url":"https://github.com/mljs/bit-array","last_synced_at":"2025-04-21T19:32:28.505Z","repository":{"id":35147382,"uuid":"39371650","full_name":"mljs/bit-array","owner":"mljs","description":"Bit-array operations in JavaScript","archived":false,"fork":false,"pushed_at":"2016-11-23T21:44:51.000Z","size":20,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-12T04:10:06.103Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/mljs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","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":"2015-07-20T08:20:12.000Z","updated_at":"2023-08-10T08:07:21.000Z","dependencies_parsed_at":"2022-09-16T15:01:28.122Z","dependency_job_id":null,"html_url":"https://github.com/mljs/bit-array","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fbit-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fbit-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fbit-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fbit-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mljs","download_url":"https://codeload.github.com/mljs/bit-array/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250120064,"owners_count":21378131,"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":"2024-11-09T20:09:14.768Z","updated_at":"2025-04-21T19:32:28.497Z","avatar_url":"https://github.com/mljs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bit-array\n\n  [![NPM version][npm-image]][npm-url]\n  [![build status][travis-image]][travis-url]\n  [![npm download][download-image]][download-url]\n\nBit-array operations in JavaScript.\n\n## Installation\n\n`npm install ml-bit-array`\n\n## Methods\n\nAll exported methods are static and do not change the original array unless indicated otherwise.  \nNumbers in array arguments are treated as 32-bit signed integers.  \nThe library is designed with speed in mind so argument type and length are not checked.\n\n### count(arr)\n\nComputes the amount of `1`s in the array. This is also known as [Hamming weight](https://en.wikipedia.org/wiki/Hamming_weight).\n\n### and(arr1, arr2)\n\nComputes the logical [AND](https://en.wikipedia.org/wiki/Logical_conjunction) operation and returns the result in a new array.\n\n### or(arr1, arr2)\n\nComputes the logical [OR](https://en.wikipedia.org/wiki/Logical_disjunction) operation and returns the result in a new array.\n\n### xor(arr1, arr2)\n\nComputes the logical [XOR](https://en.wikipedia.org/wiki/Logical_biconditional) operation and returns the result in a new array.\n\n### not(arr)\n\nComputes the logical [NOT](https://en.wikipedia.org/wiki/Negation) operation and returns the result in a new array.\n\n### getBit(arr, n)\n\nReturns `true` if the bit at position `n` is 1, `false` if it is 0.\n\nImagine that you have an array of 4-bit numbers like this `['0001', '1010']`, the 0th position will be `0` because it is the most significant bit of the 0th element of the array, and the 4th position will be `1`, because will be the most significant bit in the 1st element of the array (remember that the true number of bits for a number in this case is 32).\n\n### setBit(arr, n, val)\n\nSets the bit at position `n` to 1 if `val` is a [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) value, otherwise sets it to 0.\n\n### toBinaryString(arr)\n\nConverts an array of numbers to a string representation of the bits, so `toBinaryString([1])` will return `'00000000000000000000000000000001'`.  \nThe length of the string will be `arr.length * 32`.\n\n### parseBinaryString(str)\n\nConverts a string representation of bits to an array, so `parseBinaryString('00000000000000000000000000000010')` will return `[2]`.  \nThis is the exact inverse of `toBinaryString`.\n\n### toHexString(arr)\n\nConverts an array of numbers to a hexadecimal representation of the bits, so `toHexString([-1])` will return `'ffffffff'`.  \nThe length of the string will be `arr.length * 8`.\n\n### parseHexString(str)\n\nConverts a hexadecimal representation of bits to an array, so `parseHexString('00000010ffff0000')` will return `[16, -65536]`.  \nThis is the exact inverse of `toHexString`.\n\n### toDebug(arr)\n\nReturns a human-readable string from the array in the format:\n\n```shell\n0000: 0000 1000 1111 1000 0011 1101 1111 0001\n0020: 0000 1000 1111 1000 0011 1101 1111 0001\n0040: 0000 1000 1111 1000 0011 1101 1111 0001\n```\n\n## Authors\n\n  - [Miguel Asencio](https://github.com/maasencioh)\n  - [Michaël Zasso](https://github.com/targos)\n\n## License\n\n  [MIT](./LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/ml-bit-array.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/ml-bit-array\n[travis-image]: https://img.shields.io/travis/mljs/bit-array/master.svg?style=flat-square\n[travis-url]: https://travis-ci.org/mljs/bit-array\n[download-image]: https://img.shields.io/npm/dm/ml-bit-array.svg?style=flat-square\n[download-url]: https://npmjs.org/package/ml-bit-array\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Fbit-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmljs%2Fbit-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Fbit-array/lists"}