Working in hex

M

Mark Probert

------_=_NextPart_001_01C4337F.3888FC42
Content-Type: text/plain


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.

------_=_NextPart_001_01C4337F.3888FC42--
 
M

Mike Stok

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top