Skip to content

Instantly share code, notes, and snippets.

@calebkiage
Created January 31, 2021 23:13
Show Gist options
  • Save calebkiage/51ed2f44a47ee6b87ef938e8ee2a2341 to your computer and use it in GitHub Desktop.
Save calebkiage/51ed2f44a47ee6b87ef938e8ee2a2341 to your computer and use it in GitHub Desktop.

Revisions

  1. calebkiage created this gist Jan 31, 2021.
    13 changes: 13 additions & 0 deletions ascii-number-to-int.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    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);