Hey folks,
I modified someone else's code which converted a decimal to hex so that it would convert a string to one which a web browser can understand - IE: A space is %20. Anyway, a couple bits of just 2 lines of the code I borrowed I do not understand. They are highlighted in red below. Can anyone explain?
This is probably cake for the JavaScript gurus, but I have never seen these 2 practices before!
I modified someone else's code which converted a decimal to hex so that it would convert a string to one which a web browser can understand - IE: A space is %20. Anyway, a couple bits of just 2 lines of the code I borrowed I do not understand. They are highlighted in red below. Can anyone explain?
Code:
var Base = '0123456789ABCDEF';
function alphaToHex(w) {
var h;
var i;
var j = "";
for (c=0; c<w.length; c++) {
i = w.charCodeAt(c);
h = Base.substr([red]i&15[/red],1); [green]// What does [i]i[/i]&15 do?[/green]
while(i > 15) {
i [red]>>=[/red] 4; [green]// [i]i[/i] is greater than, is greater than and equal to 4..? What?[/green]
h = Base.substr(i&15,1) + h;
}
j += '%' + h;
}
return j;
}