language: Lua (luac 5.1.4)
date: 428 days 2 hours ago
link:
visibility: private
1
2
3
4
5
6
7
8
9
10
11
12
13
-- see http://lua-users.org/wiki/ReadWriteFormat
 
-- Write an integer in MSB order using width bytes.
function numbertobytes(num, width)
  local function _n2b(t, width, num, rem)
    if width == 0 then return table.concat(t) end
    table.insert(t, 1, string.char(rem * 0x100))
    return _n2b(t, width-1, math.modf(num/0x100))
  end
  return _n2b({}, width, math.modf(num/0x100))
end
 
io.write("<", numbertobytes(0x61626364, 4), ">\n")