Logo

Programming-Idioms

History of Idiom 76 > diff from v43 to v44

Edit summary for version 44 by steenslag:
[Ruby] removed the sprintf line, aiming for simplest solution

Version 43

2016-11-11, 16:17:34

Version 44

2017-04-20, 21:50:35

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
s = x.to_s(2)
s = "%b" % x
Code
s = x.to_s(2)
Doc URL
http://ruby-doc.org/core-2.2.3/Fixnum.html#method-i-to_s
Doc URL
http://ruby-doc.org/core-2.2.3/Fixnum.html#method-i-to_s