Well , i just wanted to say a big THANKS!!!

to Joshua for the solution,

and Jack for posting up this problem which was the same as i was

This post came up when i googled for it. And the solution mentioned
above solved my problem..

Thanks a ton!! to both of you :)

Joshua Ball wrote in post #806177:
Jack Bauer wrote:
I need it to be more like this:

"FFFFFF".whatever_magic_method # => 0xFFFFFF
I think at this point, the issue is that you need to deal with how to
display the integer, not conver ti.
"FF".to_i(16) produces the INTEGER: 255 which is the same as 0xFF.

So, if you want to display the INTEGER 255 as hex, use either printf
"0x%0x" or to_s(16). For instance:

Ruby code:
s = "0xFF"
puts "Convert string [#{s}] to an integer:"
n = s.to_i(16)
puts "normal puts: #{n}"
printf "printf in hex: 0x%x\n", n
puts "using to_s(16): #{n.to_s(16)}"

Convert string [0xFF] to an integer:
normal puts: 255
printf in hex: 0xff
using to_s(16): ff

Hope that helps.
Posted via http://www.ruby-forum.com/.

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
grouprubyonrails-talk @
postedJan 16, '12 at 12:57p
activeJan 16, '12 at 12:57p

1 user in discussion

Anna T.: 1 post



site design / logo © 2022 Grokbase