Why is the loop necessary in the second one? I had something like these which I haven't used much yet:
function base10toHex(%num)
{
%s = "0123456789ABCDEF";
%num = mFloor(%num);
return getSubStr(%s,(%num - (%num % 16)) / 16,1) @ getSubStr(%s,(%num % 16),1);
}
function numToChar(%x)
{
%num = base10toHex(%x);
eval("%char = \"\\x" @ %num @ "\";");
return %char;
}
I didn't know that collapseEscape existed for this purpose, so this looks like it'd be shorter:
function numToChar(%x)
{
%num = base10toHex(%x);
%char = collapseEscape("\\x" @ %num);
return %char;
}
My solution for the first one was just a few large switch statements (
case "\x51": return 81; works with input
charToNum("Q")) so whether that's faster than the loop or not I don't know. Incidentally a switch statement errors after about 83 cases and doesn't work.
They should both test for
16*%x + %y otherwise it's getting most of the cases wrong.