Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting to hex (Newbie) 1

Status
Not open for further replies.

digitalwm

Programmer
Mar 16, 2005
1
RO
I have a question. How can i convert a number from decimal to hex in ruby, only with rubby built in functions? An example will be apreciated, or even a link to some documentation. I have read the Official Manual, many many times, i haven't found nothing to meet my request. I used even ".pack" and ".unpack" but they don't work.

EX:
i have a number "nr=37"
how do i find oout the value in hexa on nr?

Thank You
 
You have to convert items using methods such as String#to_i(base=10)and Fixnum#to_s(base=10). These would be for decimal values. Change to (base=16) for hexadecimal values, (base=2) for binary values, etc.

For getting answers on Ruby I highly suggest the Ruby IRC channel #ruby-lang on irc://irc.freenode.net as well as checking out the Ruby mailing list archives at That's where I go since the Ruby Forum has been down for awhile now at
Hope this helps. Enjoy Ruby!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top