Last active
October 20, 2020 05:48
-
-
Save EmmanuelOga/e8c15937a03f71ea1f86a0e5c5a9cbcf to your computer and use it in GitHub Desktop.
Return least and most significant bits of a number.
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
function lsbMsb(bits) { | |
if (!bits) return {lsb: undefined, msb: undefined}; | |
let lsb = 0; | |
for (; lsb < 31 && (bits & 1) === 0; bits >>= 1) { | |
lsb++; | |
} | |
let msb = lsb; | |
for (bits >>= 1; msb < 31 && bits !== 0; bits >>= 1) { | |
msb++; | |
} | |
return {lsb, msb}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment