From: John Johnson Date: 2006-09-01T01:47:43+09:00 Subject: Re: Integer to byte string - Speed improvements On Thu, 31 Aug 2006 12:20:32 -0400, Phrogz wrote: > I'm writing code that needs to store an integer as a sequence of bytes. > Array#pack works for 1-, 2-, and 4-byte integers, but I want to be able > to support Bignums as well. s = Marshal.dump(0xCC8080808080808080808080808080808080808080808080808080808080AA) bytes = s[5..-2] bytes.each_byte { |b| print "%02x " % b } aa 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 cc (low byte first, as you mentioned) or if you prefer: rev_bytes = bytes.reverse rev_bytes.each_byte { |b| print "%02x " % b } As far as it being faster, dunno, probably. Here's the benchmark: irb(main):041:0> Process.times { s=Marshal.dump(0xCC8080808080808080808080808080808080808080808080808080808080AA) } => # Regards, JJ -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/