Cisplatin Cisplatin - 1 year ago 57
Ruby Question

Ruby: How to convert a list of integers into a hexadecimal string?

I have an array of integers that range from

, each representing two hexadecimal digits. I want to convert this array into one hexadecimal string using Ruby. How would I do that?

Answer Source

I would do something like this:

array = [0, 128, 255] { |number| number.to_s(16).rjust(2, '0') }.join
#=> "0080ff"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download