Created
January 31, 2021 23:13
-
-
Save calebkiage/51ed2f44a47ee6b87ef938e8ee2a2341 to your computer and use it in GitHub Desktop.
Converts ASCII numbers to Integers using Logical AND
This file contains hidden or 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
| const buffer = Buffer.from("9999999999", "ascii"); | |
| const mask = 15; // 00001111 | |
| let result = 0; | |
| for (let i = 0; i < buffer.length; i++) { | |
| const place = 1 * (10 ** i); | |
| const pos = (buffer.length - i) - 1; | |
| result += (buffer[pos] & mask) * place; | |
| } | |
| console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment