Logo

Programming-Idioms

History of Idiom 76 > diff from v75 to v76

Edit summary for version 76 by programming-idioms.org:
[Lua] +DemoURL

Version 75

2020-11-25, 22:15:49

Version 76

2020-11-25, 22:17:42

Idiom #76 Binary digits from an integer

Create the string s of integer x written in base 2.

E.g. 13 -> "1101"

Idiom #76 Binary digits from an integer

Create the string s of integer x written in base 2.

E.g. 13 -> "1101"

Variables
s,x
Variables
s,x
Extra Keywords
int radix
Extra Keywords
int radix
Code
local s = {}

while x > 0 do
    local tmp = math.fmod(x,2)
    s[#s+1] = tmp
    x=(x-tmp)/2
end

s=table.concat(s)
Code
local s = {}

while x > 0 do
    local tmp = math.fmod(x,2)
    s[#s+1] = tmp
    x=(x-tmp)/2
end

s=table.concat(s)
Demo URL
https://repl.it/@ProgIdioms/HighlevelHoneydewInformation