Convert a number into binary using ruby
def converttobinary(n)
n.to_s(2).to_i
end
if you need all the digits of the binary representation in an array..
n.to_s(2).split("").map(&:to_i)
Written by nava teja tummalapalli
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#