{"id":22192352,"url":"https://github.com/mzusin/js-bit-manipulation","last_synced_at":"2025-03-24T20:45:00.040Z","repository":{"id":175380361,"uuid":"653796866","full_name":"mzusin/js-bit-manipulation","owner":"mzusin","description":"A collection of bit manipulation helpers written TypeScript.","archived":false,"fork":false,"pushed_at":"2024-03-02T21:25:00.000Z","size":185,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-30T01:18:25.036Z","etag":null,"topics":["bit-manipulation","bitwise","bitwise-operators","leetcode","leetcode-javascript","leetcode-solutions","lsb","msb","number-systems","xor"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/mzusin.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}},"created_at":"2023-06-14T18:54:03.000Z","updated_at":"2023-06-23T13:07:26.000Z","dependencies_parsed_at":"2024-03-02T22:20:28.988Z","dependency_job_id":"cd4cb8a0-6529-4aed-b0cc-133a97126103","html_url":"https://github.com/mzusin/js-bit-manipulation","commit_stats":null,"previous_names":["mzusin/js-bit-manipulation"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzusin%2Fjs-bit-manipulation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzusin%2Fjs-bit-manipulation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzusin%2Fjs-bit-manipulation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzusin%2Fjs-bit-manipulation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mzusin","download_url":"https://codeload.github.com/mzusin/js-bit-manipulation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245351761,"owners_count":20601090,"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-manipulation","bitwise","bitwise-operators","leetcode","leetcode-javascript","leetcode-solutions","lsb","msb","number-systems","xor"],"created_at":"2024-12-02T12:22:25.361Z","updated_at":"2025-03-24T20:45:00.012Z","avatar_url":"https://github.com/mzusin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🌟 Bit Manipulation in JavaScript 🌟\nA collection of bit manipulation helpers written in TypeScript.\n\nThis repository is intended for learning bit manipulation in JavaScript/TypeScript.\nYou are welcome to check the [source code](https://github.com/mzusin/js-bit-manipulation/tree/main/src/core) of each function and the [unit tests](https://github.com/mzusin/js-bit-manipulation/tree/main/test).\n\n## Table of Contents\n- [Points](#points-)\n- [Common](#common-️)\n- [Math](#math-)\n- [Predicates](#predicates-)\n- [Least Significant Bit (LSB)](#least-significant-bit-lsb-%EF%B8%8F)\n- [Most Significant Bit (MSB)](#most-significant-bit-msb-)\n- [Working with bits](#working-with-bits-)\n- [Masks](#masks-)\n- [Number Systems](#number-systems-)\n- [Practice Problems](#practice-problems)\n- [LeetCode Solutions](#leetcode-solutions)\n\n## Points 📌\n- [Two's Complement Format](https://github.com/mzusin/js-bit-manipulation/blob/main/README/Two's%20Complement%20Format.md)\n- [AND/OR properties](https://github.com/mzusin/js-bit-manipulation/blob/main/README/AND-OR.md)\n- [XOR properties](https://github.com/mzusin/js-bit-manipulation/blob/main/README/XOR.md)\n- [NOT properties](https://github.com/mzusin/js-bit-manipulation/blob/main/README/NOT.md)\n\n## Common ✍️\n- `export const getBinaryString: (num: number) =\u003e string;`\n- `export const parseBinaryString: (str: string) =\u003e number;`\n- `export const convertToUInt32: (num: number) =\u003e number;`\n- `export const swap: (num1: number, num2: number) =\u003e number[];`\n\n## Math 💡\n- `export const multiplyBy2: (num: number) =\u003e number;`\n- `export const multiplyBy2PowerN: (num: number, n: number) =\u003e number;`\n- `export const divideBy2: (num: number) =\u003e number;`\n- `export const divideBy2PowerN: (num: number, n: number) =\u003e number;`\n- `export const toggleSign: (num: number) =\u003e number;`\n- `export const addition: (num1: number, num2: number) =\u003e number;`\n- `export const subtraction: (num1: number, num2: number) =\u003e number;`\n- `export const multiplication: (num1: number, num2: number) =\u003e number;`\n\n## Predicates 🔬\n- `export const isEven: (num: number) =\u003e boolean;`\n- `export const isOdd: (num: number) =\u003e boolean;`\n- `export const isEquals: (num1: number, num2: number) =\u003e boolean;`\n- `export const isNegative: (num: number) =\u003e boolean;`\n- `export const isPositive: (num: number) =\u003e boolean;`\n\n## Least Significant Bit (LSB) ⚗️\n- `export const getLSB: (num: number) =\u003e number;`\n- `export const removeLSB: (num: number) =\u003e number;`\n- `export const setLSB: (num: number) =\u003e number;`\n- `export const unsetLSB: (num: number) =\u003e number;`\n- `export const toggleLSB: (num: number) =\u003e number;`\n\n## Most Significant Bit (MSB) 🤔\n- `export const getMSB: (num: number) =\u003e number;`\n- `export const setMSB: (num: number) =\u003e number;`\n- `export const unsetMSB: (num: number) =\u003e number;`\n\n## Working with bits 🧩\n- `export const setBitAtPosition: (num: number, n: number) =\u003e number;`\n- `export const unsetBitAtPosition: (num: number, n: number) =\u003e number;`\n- `export const toggleBitAtPosition: (num: number, n: number) =\u003e number;`\n- `export const isBitSetAtPosition: (num: number, n: number) =\u003e boolean;`\n- `export const invertBits: (num: number) =\u003e number;`\n- `export const countSetBits: (num: number) =\u003e number;`\n- `export const countUnsetBits: (num: number) =\u003e number;`\n- `export const getRightmostSetBit: (num: number) =\u003e number;`\n\n## Masks 🎭\n- `export const getNSetBitsMask: (n: number) =\u003e number;`\n\n## Number Systems 🔮\n- `export const binaryToHex: (num: number) =\u003e string;`\n- `export declare const binaryToDecimal: (nums: number[]) =\u003e number;`\n\n------------------------\n\n## Practice Problems\n- [Bit Manipulation on leetcode.com](https://leetcode.com/tag/bit-manipulation/)\n\n## LeetCode Solutions\nSolutions to LeetCode problems in JavaScript using bit manipulations approach only.\n- [1684. Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings/solutions/3646136/javascript-bit-manipulation-with-comments-9982/)\n- [2220. Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number/solutions/3649410/javascript-bit-manipulation/)\n- [338. Counting Bits](https://leetcode.com/problems/counting-bits/solutions/3657019/javascript-bit-manipulation/)\n- [461. Hamming Distance](https://leetcode.com/problems/hamming-distance/solutions/3660282/javascript-bit-manipulation/)\n- [136. Single Number](https://leetcode.com/problems/single-number/solutions/2007647/javascript-xor/)\n- [476. Number Complement](https://leetcode.com/problems/number-complement/solutions/3660762/javascript-99-42/)\n- [191. Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/solutions/3665456/javascript-3-solutions/)\n- [405. Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal/solutions/3673530/javascript-bit-manipulation/)\n- [342. Power of Four](https://leetcode.com/problems/power-of-four/solutions/3673730/javascript-math-bit-manipulation-solutions/)\n\n--------------\n\n``` \n       (                      (    (         \n   (   )\\ )  *   )  (  (      )\\ ) )\\ )      \n ( )\\ (()/(` )  /(  )\\))(   '(()/((()/( (    \n )((_) /(_))( )(_))((_)()\\ )  /(_))/(_)))\\   \n((_)_ (_)) (_(_()) _(())\\_)()(_)) (_)) ((_)  \n | _ )|_ _||_   _| \\ \\((_)/ /|_ _|/ __|| __| \n | _ \\ | |   | |    \\ \\/\\/ /  | | \\__ \\| _|  \n |___/|___|  |_|     \\_/\\_/  |___||___/|___| \n```  \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmzusin%2Fjs-bit-manipulation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmzusin%2Fjs-bit-manipulation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmzusin%2Fjs-bit-manipulation/lists"}