Blockland Forums > Modification Help

Hexadecimal conversion

Pages: (1/1)

Bauklotz:


--- Code: ---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);
}

--- End code ---

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.

Ephialtes:

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

Bauklotz:

Oh yes, thank you. That fixed it.

Pages: (1/1)

Go to full version