potrebuju co nejednoduseji a nejefektneji previst text do hexa kodu, mate nejaky navrhy? nejsem moc velky znalec javascriptu. diky
Printable View
potrebuju co nejednoduseji a nejefektneji previst text do hexa kodu, mate nejaky navrhy? nejsem moc velky znalec javascriptu. diky
Mas stesti, to jsem taky potreboval takze tu to mas (nedelal jsem to ja ;))
Pokud to potrbujes prevest ze stringu tak to volas nejak takhle:Kód:var symbols = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
function num2num(num) {
base = symbols.length;
octal = new Array();
i = 0; // init counter
while(num >= base) {
tmp = Math.floor(num/base);
octal[i] = num - tmp * base;
num = tmp;
i++; // increment counter
}
octal[i] = num; // the reminder smaller than base
rval = ""; // preparing the return value
for(n = i; n >= 0; n--) rval += symbols[octal[n]];
return rval;
}
Kód:x=num2num(parseInt(y));
Sice nevim co to presne dela, ale zjistil sem presne to co sem potreboval.
metoda .toString(16) to je vse co sem chtel.
pak sem to pouzil v takto :
Kód:function text2hex()
{
hex.value = "";
delka = text.value.length;
for(i = 0;i<delka;i++)
{
hex.value += text.value.charCodeAt(i).toString(16);
}
}