Well, as Patrick said , converting the past is not required using Array\#pack.
irb> [99.0].pack('G').split('').map { |ds| ds[0] }
#=> [64, 88, 192, 0, 0, 0, 0, 0]
irb> _.map { |d| "%02x" % d }
#=> ["40", "58", "c0", "00", "00", "00", "00", "00"]
irb> [99.0].pack('E').split('').map { |ds| ds[0] }
#=> [0, 0, 0, 0, 0, 192, 88, 64]
irb> _.map { |d| "%02x" % d }
#=> ["00", "00", "00", "00", "00", "c0", "58", "40"]
So, it depends on whether you want to unpack it using the high byte at the zero index or the low byte at the zero index:
E | Double-precision float, little-endian byte order
G | Double-precision float, network (big-endian) byte order
source
share