Thursday, 19 September 2013

Ruby add an integer to a hex value or convert integer to hex

Ruby add an integer to a hex value or convert integer to hex

I am trying to convert an integer to hex in ruby but i am having trouble.
I need it to be in the format \x00 but it seems this is not possible if
you do not set it manually?
count = 5
hex = "\x0#{count}"
puts hex.inspect # "\x005" but i need it to be "\x05"
Thanks!

No comments:

Post a Comment