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: 1130 / 503
Referenced in: #357 - Aibo finder v2
#378 - RS Image Hash Function
#380 - hashImage (include)
#415 - Rough-Hash Function
#424 - LXTerminal Contents Finder
#425 - LXTerminal Contents Segmenter
#426 - LXTerminal Contents Recognizer
#427 - LXTerminal character reference maker
#428 - LXTerminal Contents Finder (include)
#429 - LXTerminal character reference maker 2
#432 - LXTerminal Contents Recognizer 2
#437 - LXTerminal Contents Recognizer 2 (cursor line only)
#438 - LXTerminal Contents Recognizer 2 (repeatable)
#439 - LXTerminal Contents Recognizer 2 (cursor line only, repeatable)
#462 - Scrollbar finder 1
#484 - Image distinguisher by randomly selected color
#487 - Image distinguisher by randomly selected color [learner part]
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)