Skip to content

Instantly share code, notes, and snippets.

@lunks
Created April 27, 2010 22:38
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 lunks/381437 to your computer and use it in GitHub Desktop.
Save lunks/381437 to your computer and use it in GitHub Desktop.
# Converting to binary, hexadecimal, ASCII, etc.
number = 100
base = 2
# syntax:
numero.to_s(base)
# => "1100100"
number.to_s(16)
@ => "64"
# to do the other way around, just input the number on any base and use to_i(base)
"1100100".to_i(2)
# => 100
# Integer to ASCII
65.chr
# => "A"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment