Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ta = { ... }
- local img = ta[1]
- local to = ta[2]
- local function getbin(baseten)
- local bin = ""
- local binkey = "01"
- local rim
- while baseten > 0 do
- rim = math.floor(baseten%2)
- bin = binkey:sub(rim+1,rim+1) .. bin
- baseten = math.floor(baseten/2)
- end
- if(#bin < 4)then
- bin = string.rep("0",4-#bin) .. bin
- end
- return bin
- end
- local function imgtobin(img)
- local f = fs.open(img,'r')
- local cont = f.readAll()
- local ndata = ""
- f.close()
- cont = cont:gsub(string.char(32),"")
- for line in cont:gmatch("[^\n]+") do
- for i=1, #line do
- nline = tonumber(line:sub(i,i),16)
- print(nline)
- ndata = ndata .. " " .. getbin(nline)
- end
- ndata = ndata .. "\n"
- end
- return ndata
- end
- local data = imgtobin(img)
- local export = fs.open(to .. ".bin","w")
- export.write(data)
- export.close()
- print("Bin exported to: " .. to .. ".bin")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement