Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

13
LINES

< > BotCompany Repo | #356 // num2hex

Lua code

-- Returns HEX representation of num
-- minlen is optional 
function num2hex(num, minlen)
  minlen = minlen or 1
  local hexstr = '0123456789abcdef'
  local s = ''
  while num > 0 or #s < minlen do
    local mod = math.fmod(num, 16)
    s = string.sub(hexstr, mod+1, mod+1) .. s
    num = math.floor(num / 16)
  end
  return s
end

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #356
Snippet name: num2hex
Eternal ID of this version: #356/1
Text MD5: 32f9b49efbc5d929b47cd7c61c10f568
Author: stefan
Category: string functions
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-01-28 20:47:53
Source code size: 342 bytes / 13 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 1069 / 483
Referenced in: [show references]