Posted By

ukpyr on 03/13/09


Tagged

hex lua


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

CobaltHex
Tyster


Number to HEX


 / Published in: Lua
 

  1. --- Returns HEX representation of num
  2. function num2hex(num)
  3. local hexstr = '0123456789abcdef'
  4. local s = ''
  5. while num > 0 do
  6. local mod = math.fmod(num, 16)
  7. s = string.sub(hexstr, mod+1, mod+1) .. s
  8. num = math.floor(num / 16)
  9. end
  10. if s == '' then s = '0' end
  11. return s
  12. end

Report this snippet  

You need to login to post a comment.