Guest User

telegraph

a guest
Jul 29th, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.80 KB | None | 0 0
  1. function decBin(dec)
  2.   local result = " "
  3.   repeat
  4.         local divres = dec / 2
  5.         local int, frac = math.modf(divres)
  6.         dec = int
  7.         result = math.ceil(frac) .. result
  8.   until dec == 0
  9.   local StrNumber
  10.   StrNumber = string.format(result, "s")
  11.   local nbZero
  12.   nbZero = 16 - string.len(StrNumber)
  13.   local Sresult
  14.   Sresult = string.rep("0", nbZero)..StrNumber
  15.   return Sresult
  16. end
  17. function binDec(bin)
  18.   local num = 0
  19.   local ex = string.len(bin) - 1
  20.   local l = 0
  21.   l = ex + 1
  22.   for i = 1, l do
  23.   b = string.sub(bin, i ,i)
  24.   if b == "1" then
  25.       num = num + 2^ex
  26.   end
  27.   ex = ex - 1
  28.   end
  29.   return num
  30. end
  31. term.setCursorPos(1,1)
  32. term.write("Please type a message to be sent.")
  33. term.setCursorPos(1,2)
  34. local input = read()
  35. local textLength = string.len(input)
Advertisement
Add Comment
Please, Sign In to add comment