Some favorite site feeds aggregated locally: iPhone Development RSS   Adobe Labs RSS   Macrumors RSS

Friday, June 13, 2008

Found this code laying around: string2Bin(s)

Friday, June 13, 2008   

This probably isn't very useful to many, but I found a little code to translate a String into a binary representation.

function string2Bin(s:String)
{
var b = new Array();
var last = s.length;
for (var i = 0; i <>
{
var d = s.charCodeAt(i);
if (d <>
b[i] = dec2Bin(d);
else {
var c = s.charAt(i);
b[i] = -1;
}
}
return b;
}

function dec2Bin(d:uint)
{
var b = '';
for (var i = 0; i <>
{
b = (d%2) + b;
d = Math.floor(d/2);
}
return b;
}
//01000101,01110010,01101001,01100011
trace( string2Bin("Eric") );

 
 Return to the main page
Comments:

There are currently 0 Comments:

 Leave a comment