From: Mike Stok Date: 2004-05-07T01:09:09+09:00 Subject: Re: Working in hex "Mark Probert" writes: > 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. 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