Skip to content

Instantly share code, notes, and snippets.

@itspriddle
Created February 10, 2010 00:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itspriddle/299865 to your computer and use it in GitHub Desktop.
Save itspriddle/299865 to your computer and use it in GitHub Desktop.
# Convert dec => hex and hex => dec
def decimal_to_hex(number)
res = number.to_i.to_s(16)
res = "0" * (12 - res.length) << res if res.length < 12
res
end
def hex_to_decimal(number)
"0x#{number}".hex
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment