Signed hex conversion

I’d like to convert a string representing a 32 bit signed number like:
“FFFFFFC4” or “0xFFFFFFC4”
into the integer value
-60
or a string like
“-60”
and am not having a lot of luck with .hex, to_s, and .to_i.

Any help would be appreciated.
– Tony K.

There’s probably a better way, but:

[0xFFFFFFC4].pack(“l”).unpack(“l”)[0] # => -60

– Dossy

···

On 2002.09.19, akolarik@sonexis.com akolarik@sonexis.com wrote:

I’d like to convert a string representing a 32 bit signed number like:
“FFFFFFC4” or “0xFFFFFFC4”
into the integer value
-60
or a string like
“-60”
and am not having a lot of luck with .hex, to_s, and .to_i.

Any help would be appreciated.
– Tony K.


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)