fork download
  1. -- see http://l...content-available-to-author-only...s.org/wiki/ReadWriteFormat
  2.  
  3. -- Write an integer in MSB order using width bytes.
  4. function numbertobytes(num, width)
  5. local function _n2b(t, width, num, rem)
  6. if width == 0 then return table.concat(t) end
  7. table.insert(t, 1, string.char(rem * 0x100))
  8. return _n2b(t, width-1, math.modf(num/0x100))
  9. end
  10. return _n2b({}, width, math.modf(num/0x100))
  11. end
  12.  
  13. io.write("<", numbertobytes(0x61626364, 4), ">\n")
Success #stdin #stdout 0.02s 2540KB
stdin
Standard input is empty
stdout
<abcd>