From: Brian Candler Date: 2011-04-07T18:41:02+09:00 Subject: Re: Packing and unpacking unsigned integers of arbitrary size as binary strings Aaron D. Gifford wrote in post #991376: > Are there alternatives that may be more efficient, or if I've missed > something obvious. I'd just do this: >> num = 12345678901234567890 => 12345678901234567890 >> hex = num.to_s(16) => "ab54a98ceb1f0ad2" >> hex.size => 16 >> [hex].pack("H*") => "\253T\251\214\353\037\n\322" Add an extra '0' to the left of hex if it's an odd number of characters. -- Posted via http://www.ruby-forum.com/.