Skip to content

Instantly share code, notes, and snippets.

@edulan
Created July 8, 2010 10:42
Show Gist options
  • Save edulan/467871 to your computer and use it in GitHub Desktop.
Save edulan/467871 to your computer and use it in GitHub Desktop.
/**
* Returns the binary representation of a number
*
* @param A number
* @return A string of 1's and 0's
*/
private function toBinary(n:Number):String {
var s:String = "";
var i:Number = 0;
var b:Number = n >> i;
while (b > 0) {
var d:String = (b & 1) ? "1" : "0";
b = n >> ++i;
s = d + s;
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment