-1

I have code as below:

x = readsomevalue();

print x

The printed value is an integer. I want this in hex but,

The integer which is returned(x) is having leading 0 in it(ex. 0543676). for this the standard method fails

x.to_s(16) = 0

how to solve this? since some of you have marked it as duplicate let me tell you, that the standard call fails when we have leading 0 in it, so is there anything to eliminate leading 0.

goal4321
  • 121
  • 3
  • 17

2 Answers2

1

Fixnum#to_s

255.to_s(16) # => "ff"
sawa
  • 165,429
  • 45
  • 277
  • 381
0

Kernel#format:

'%x' % 255 # => "ff"
Boris Stitnicky
  • 12,444
  • 5
  • 57
  • 74