Logo

Programming-Idioms

History of Idiom 76 > diff from v25 to v26

Edit summary for version 26 by :

Version 25

2015-09-03, 15:45:24

Version 26

2015-09-03, 15:46:11

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"

Code
base = 2
s = x.to_s(base)
Code
s = x.to_s(2)
s = "%b" % x
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