function CreateHexFile(FileName, Content) if type(Content) == "table" then Content = table.concat(Content, "") end if type(Content) == "string" then Content = string.gsub(Content, "[^abcdefABCDEF%d]", "") end local file, err = io.open(FileName, "wb") if not file then return 0 end if (#Content % 2 == 1) then Content = Content .. "0" end local bytes = "" for i=1,#Content,2 do bytes = bytes .. string.char(tonumber(Content:sub(i, i+1), 16)) end file:write(bytes) file:close() return 1 end print("This program creates a file and write the following bytes into it:\n") CharTable = "" for i = 0, 255 do CharTable = CharTable .. string.format("%02x ", i) end print(CharTable) if CreateHexFile("C:\\DESKTOP\\ASCIILUA.BIN", CharTable) then print("\nFile was written successfully.\n") else print("\nFile write failed.\n") end