diff options
-rw-r--r-- | binaryLib.lua | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/binaryLib.lua b/binaryLib.lua index cf8a167..3d5c9c6 100644 --- a/binaryLib.lua +++ b/binaryLib.lua @@ -18,9 +18,11 @@ end -- continue to divide by two until quotient is zero function toBits(num) local t = {} + local cnt = 0 while num > 0 do + cnt = cnt + 1 remainder = num % 2 -- Basics of binary. If num is divisible by two, 0 in table. If not, 1 in table - table.insert(t, remainder)-- defaults to #t+1 key + t[cnt] = remainder -- defaults to #t+1 key num = (num - remainder)/2 --num = math.floor((num - remainder)/2) -- carry out calculation -- note math.floor used here to eliminate floating values |