Instantly share code, notes, and snippets.

Embed
What would you like to do?
Method to convert a number to a binary string
class Fixnum
def to_bin_s
return '0' if self == 0
s = ''
n = self
while n > 0
s = (n % 2).to_s << s
n = n >> 1
end
s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment