Logo

Programming-Idioms

History of Idiom 76 > diff from v44 to v45

Edit summary for version 45 by Bug38:
New Lua implementation by user [Bug38]

Version 44

2017-04-20, 21:50:35

Version 45

2017-08-21, 13:21:07

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"

Extra Keywords
int radix
Extra Keywords
int radix
Code
local x = 13
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)