Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Roblox (JimmyChance):
- local module = {}
- module.toByte = function(v)
- if type(v) == "number" then return tostring(v) end
- return v:gsub(".", function(t) return " " .. t:byte() end):gsub("^%s*", "")
- end
- module.toChar = function(v)
- if type(v) == "number" then return v end
- return (" " .. v):gsub("(%s*)(%d+)", function(_, char)
- return char:char()
- end)
- end
- module.toDecimal = function(v)
- return tostring(v):gsub("%d+", function(bin)
- local returned = 0
- for i = 1, #bin do
- local place = 2^(i - 1)
- returned = returned + place * tonumber(bin:sub(-i, -i))
- end
- return returned
- end)
- end
- module.toBinary = function(v)
- return module.toByte(v):gsub("%d+", function(char)
- local number = tonumber(char)
- local returned = ""
- while math.floor(number/2) > 0 do
- local remainder = number % 2
- returned = returned .. remainder
- number = math.floor(number/2)
- end returned = returned .. number
- return ("%08d"):format(tonumber(returned:reverse()))
- end)
- end
- _G.module = module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement