summaryrefslogtreecommitdiff
path: root/binaryLib.lua
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2021-06-02 14:14:22 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2021-06-02 14:15:57 -0400
commit5dd2629e28291c58f41a70cf3de478cfc7ae3db8 (patch)
tree81875cb7f6ad0761988df9fc091f86b2f927d6b2 /binaryLib.lua
parenta615d23b65291307929b2a2542b594a7dc5b8f2d (diff)
downloadnodeMCU_rf_source_lmx2487-5dd2629e28291c58f41a70cf3de478cfc7ae3db8.tar.gz
nodeMCU_rf_source_lmx2487-5dd2629e28291c58f41a70cf3de478cfc7ae3db8.zip
avoid using insert and instead use index for num to bit conversionv1.0-home-cooked-binary
Diffstat (limited to 'binaryLib.lua')
-rw-r--r--binaryLib.lua4
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