Quote:
Originally posted by fospher.com
Right, there's many convertors out there, I was looking for a manual way. Im looking through your source right now argo in the strtobit function, but frankly not understanding it. Sorry, I guess I turned into a thick designer...:(
actually flash does all the work for you:code:
function strToBin(lqlstr) {
//create and array, each element in the array is a character of the string,
//so if you right "apple" the array is "a,p,p,l,e"
var charArray = lqlstr.split("");
var i = 0;
//i go through each element in the array and call the chartobin function for each element (that means i call the function for each letter
while (i<charArray.length) {
charArray[i] = (charToBin(charArray[i]));
i++;
}
return charArray.join("");
}
//take a character as a parameter
function charToBin(lqlchar) {
//get the character code (which is a number) of the letter
var code = lqlchar.charCodeAt(0);
//here, convert the code (number) to a number with base 2 (binary) and still, use it as a string
//then add 4 0000, just in case, to the beginning of the string (cause the minimum number it will return, is a 4 digit number (but i need 8 digits, for it to be a byte, i believe)
//so, you ll have something like "00001111"
//or "000012345678"
var bincode = "0000"+code.toString(2);
//here, i just make sure that the return code has 8 digits
//so if it is "00001234567" it will be cut to "01234567"
bincode = bincode.substr(-8, 8);
return bincode;
}