Share this page 

Convert a number to hexadecimalTag(s): Powerscript


[of_long2hex(long alnumber, integer ai_digit) returns a string]

long ll_temp0, ll_temp1
char lc_ret

IF ai_digit > 0 THEN
   ll_temp0 = abs(al_number / (16 ^ (ai_digit - 1)))
   ll_temp1 = ll_temp0 * (16 ^ (ai_digit - 1))
   IF ll_temp0 > 9 THEN
      lc_ret = char(ll_temp0 + 55)
   ELSE
      lc_ret = char(ll_temp0 + 48)
   END IF
   RETURN lc_ret + &
          of_long2hex(al_number - ll_temp1 , ai_digit - 1)
END IF
RETURN ""

// of_longhex(256, 4) returns  "0100"
// of_longhex(256, 3) returns  "100"

See this HowTo for hex2long conversion.