Last active
October 30, 2018 14:15
-
-
Save yspreen/6523b54c8f696265d0bec3f6487c6581 to your computer and use it in GitHub Desktop.
JS snippets
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 toBin(i) { | |
let s = "", flip = i < 0; | |
i = flip ? ~i : i; | |
while (i != 0) { | |
s = (flip ? 1 - (i & 1) : (i & 1)) + s; | |
i >>= 1; | |
} | |
return (flip ? "…1" : "") + (s == "" ? (flip ? "1" : "0") : s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment