Created
November 19, 2011 18:17
-
-
Save mattneary/1379160 to your computer and use it in GitHub Desktop.
Decimal to Binary
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
function( | |
n, //Number | |
i,a //PLaceholders | |
){ | |
for( //Loop | |
a=[i=0]; //Initialize (Avoid comma in assignment) | |
a[i]=n>>i&1, //Save bit | |
n>>i++; //Check if there are more bits and increment | |
); | |
return a | |
} |
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
function(n,i,a){for(a=[i=0];a[i]=n>>i&1,n>>i++;);return a} |
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
{ | |
"name": "Decimal to Binary", | |
"description": "Converts decimal number into an array of bits", | |
"contributors": [ | |
"mattneary" | |
], | |
"keywords": [ | |
"binary", | |
"bitwise" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment