From: ara.t.howard@... Date: 2006-09-23T00:13:20+09:00 Subject: Re: 64-bit integers in network byte-order On Fri, 22 Sep 2006, Francis Cianfrocca wrote: > All, > does Ruby have a way to convert 64-bit integers to and from network > order in a platform-independent way? > > For 32-bit ints, I can use [value].pack("N"). The conversion operator > for 64-bit ints ("Q") doesn't have a network-order variant. (I assume > this is because the underlying byte-order converters (htons/htonl) don't > have a 64-bit version on 32-bit platforms.) i don't know the answer, but maybe a hack? harp:~ > cat a.rb class String LITTLE_ENDIAN = ([42].pack('i')[0] == 42) BIG_ENDIAN = !LITTLE_ENDIAN def hton!() BIG_ENDIAN ? self : replace(reverse) end def hton() dup.hton! end def noth!() BIG_ENDIAN ? self : replace(reverse) end def noth() dup.noth! end end forty_two = [42].pack('Q') p forty_two forty_two = [42].pack('Q').hton! p forty_two harp:~ > ruby a.rb "*\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000*" also, maybe joel's bitstruct package http://redshift.sourceforge.net/bit-struct/doc/index.html regards. -a -- in order to be effective truth must penetrate like an arrow - and that is likely to hurt. -- wei wu wei