Author Topic: Hexadecimal conversion  (Read 405 times)

Code: [Select]
function mDecToHex(%dec) {
   %res = %dec % 16;
   if(%dec-%res == 0)
      return mGetHexChar(%res);
   else
      return mDecToHex((%dec-%res)/16) @ mGetHexChar(%res);
}
function mHexToDec(%hex) {
   for(%i=0;%i<strLen(%hex);%i++) {
      %a = getSubStr(%hex,%i,1);
      switch$ (%a) {
         case A: %a = 10;
         case B: %a = 11;
         case C: %a = 12;
         case D: %a = 13;
         case E: %a = 14;
         case F: %a = 15;
      }
      %b += %a * mPow(16, (strLen(%hex)-1)-%i);
   }
   return %b;
}
function mGetHexChar(%num) {
   return getSubStr("0123456789ABCDEF", %num, 1);
}

I tried making hexadecimal conversation functions, but apparantly the mDecToHex does not work. For example, converting 701 to hex with that function returns 2, whereas the valid output would be 2BD.
« Last Edit: January 05, 2011, 10:17:42 AM by Bauklotz »

Looks like you're trying to concatenate on L6 with a plus sign.

Oh yes, thank you. That fixed it.