Created
February 2, 2022 18:22
-
-
Save AndrewIngram/f7184b580fd35193a9c2e0636fae8dd3 to your computer and use it in GitHub Desktop.
Apply bitmask and shift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Given an input and a mask, will return just part we care about | |
* | |
* e.g. | |
* input: 0b11101111 | |
* mask: 0b00110000 | |
* returns: 0b10 | |
*/ | |
function maskedValue(input: number, mask: number): number { | |
return (input & mask) >> Math.log2(mask & -mask); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment