Skip to content

Instantly share code, notes, and snippets.

@alexbowe
Created November 22, 2010 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbowe/709642 to your computer and use it in GitHub Desktop.
Save alexbowe/709642 to your computer and use it in GitHub Desktop.
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