A collection of bit manipulation helpers written in TypeScript.
This repository is intended for learning bit manipulation in JavaScript/TypeScript. You are welcome to check the source code of each function and the unit tests.
- Points
- Common
- Math
- Predicates
- Least Significant Bit (LSB)
- Most Significant Bit (MSB)
- Working with bits
- Masks
- Number Systems
- Practice Problems
- LeetCode Solutions
export const getBinaryString: (num: number) => string;
export const parseBinaryString: (str: string) => number;
export const convertToUInt32: (num: number) => number;
export const swap: (num1: number, num2: number) => number[];
export const multiplyBy2: (num: number) => number;
export const multiplyBy2PowerN: (num: number, n: number) => number;
export const divideBy2: (num: number) => number;
export const divideBy2PowerN: (num: number, n: number) => number;
export const toggleSign: (num: number) => number;
export const addition: (num1: number, num2: number) => number;
export const subtraction: (num1: number, num2: number) => number;
export const multiplication: (num1: number, num2: number) => number;
export const isEven: (num: number) => boolean;
export const isOdd: (num: number) => boolean;
export const isEquals: (num1: number, num2: number) => boolean;
export const isNegative: (num: number) => boolean;
export const isPositive: (num: number) => boolean;
export const getLSB: (num: number) => number;
export const removeLSB: (num: number) => number;
export const setLSB: (num: number) => number;
export const unsetLSB: (num: number) => number;
export const toggleLSB: (num: number) => number;
export const getMSB: (num: number) => number;
export const setMSB: (num: number) => number;
export const unsetMSB: (num: number) => number;
export const setBitAtPosition: (num: number, n: number) => number;
export const unsetBitAtPosition: (num: number, n: number) => number;
export const toggleBitAtPosition: (num: number, n: number) => number;
export const isBitSetAtPosition: (num: number, n: number) => boolean;
export const invertBits: (num: number) => number;
export const countSetBits: (num: number) => number;
export const countUnsetBits: (num: number) => number;
export const getRightmostSetBit: (num: number) => number;
export const getNSetBitsMask: (n: number) => number;
export const binaryToHex: (num: number) => string;
export declare const binaryToDecimal: (nums: number[]) => number;
Solutions to LeetCode problems in JavaScript using bit manipulations approach only.
- 1684. Count the Number of Consistent Strings
- 2220. Minimum Bit Flips to Convert Number
- 338. Counting Bits
- 461. Hamming Distance
- 136. Single Number
- 476. Number Complement
- 191. Number of 1 Bits
- 405. Convert a Number to Hexadecimal
- 342. Power of Four
( ( (
( )\ ) * ) ( ( )\ ) )\ )
( )\ (()/(` ) /( )\))( '(()/((()/( (
)((_) /(_))( )(_))((_)()\ ) /(_))/(_)))\
((_)_ (_)) (_(_()) _(())\_)()(_)) (_)) ((_)
| _ )|_ _||_ _| \ \((_)/ /|_ _|/ __|| __|
| _ \ | | | | \ \/\/ / | | \__ \| _|
|___/|___| |_| \_/\_/ |___||___/|___|