Hello, rubyists.
I need to do the following:
val = 0xe8b8 + (4 * 110).hex
= 0xe8b8 + 1b8
= 0xea70
Is there an easy way in Ruby of doing this?
I need to have the result in hex.
-mark.
Hello, rubyists.
I need to do the following:
val = 0xe8b8 + (4 * 110).hex
= 0xe8b8 + 1b8
= 0xea70
Is there an easy way in Ruby of doing this?
I need to have the result in hex.
-mark.
What about:
irb(main):001:0> val = 0xe8b8 + (4 * 110)
=> 60016
irb(main):002:0> val.to_s(16)
=> “ea70”
I think you are confused between the internal representation of a number
and its text representation.
Guillaume.
On Thu, 2004-05-06 at 11:31, Mark Probert wrote:
Hello, rubyists.
I need to do the following:
val = 0xe8b8 + (4 * 110).hex
= 0xe8b8 + 1b8
= 0xea70Is there an easy way in Ruby of doing this?
I need to have the result in hex.-mark.
“Mark Probert” probertm@nortelnetworks.com writes:
Hello, rubyists.
I need to do the following:
val = 0xe8b8 + (4 * 110).hex
= 0xe8b8 + 1b8
= 0xea70Is there an easy way in Ruby of doing this?
I need to have the result in hex.
val = sprintf(“0x%x”, 0xe8b8 + 4 * 110)
is one way to do it or
val = “0x” + (0xe8b8 + 4 * 110).to_s(16)
Hope this helps (and isn’t too ugly
Mike
–
mike@stok.co.uk | The “`Stok’ disclaimers” apply.
http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA
mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60
http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA