Philip Mak wrote: > > Is there a way to pack() a signed long in a portable fashion (i.e. it > should work on both little endian and big endian machines)? > > The pack() function has these options: > 'l' => { :signed => true, :network => false } > 'N' => { :signed => false, :network => true } > > But I cannot find an option that is { :signed => true, :network => true }! > > So if I pack with 'l', it won't work on different architectures. And > if I pack with 'N', it won't allow negative numbers. > > For now, I think I have to pack with 'N', but add 2**32 before packing > and subtract 2**32 after unpacking, but I think there ought to be a > better way? Will this do? if [1].pack("N") == [1].pack("I") # big endian array.pack("l*").reverse else array.pack("l*") end Regards, Dan -- a = [74, 117, 115, 116, 32, 65, 110, 111, 116, 104, 101, 114, 32, 82] a.push(117,98, 121, 32, 72, 97, 99, 107, 101, 114) puts a.pack("C*")