Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function dec2bin(number)
- local bin = ""
- if type(number) == "number" then
- local int, fract = math.floor(number), tostring(number):match("%d+\.(%d+)")
- while int > 0 do
- bin = "" .. (int % 2 ) .. bin
- int = math.floor(int / 2)
- end
- if fract then
- bin = bin .. "."
- for i=1, #fract do
- local it = tonumber(fract:sub(i, i))
- bin = bin .. (it > 4 and "1" or "0")
- end
- end
- return bin
- end
- return false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement