cryptography - Using toString()'s argument to output letters in javascript -
this question has answer here:
i don't understand what's happening here:
var x = 14; alert(x.tostring(36)); //alerts 'e' alert(x.tostring(16)); //also alerts 'e' x = 20; alert(x.tostring(16)); //alerts '14' alert(x.tostring(36)); //alerts 'k' i think first parameter determines numerical system of number converted, not sure. can explain in detail going on?
you changing bases passing number parameter. second example easiest explain . . . 14 in base16 'e'. base16 'digits' 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, (10), b (11), c (12), d (13), e (14), , f (15).
for number system of 15 or above, actually, 14 = 'e'.
in case of 20, base16 gives 14, cause have 1 sixteen, plus 4 ones (16 + 4 = 20).
to level set, in decimal (base10 . . . system used to), 14 technically 1 ten plus 4 ones.
if not familiar different numbering systems, can take little getting used to. :)
Comments
Post a Comment