sub fix_endian { my $h = shift; my $h = reverse $h; $h =~ s/(.)(.)/$2$1/g; # only required if using 'H' not 'h' template return $h; } sub hex2int { unpack("N", pack("H8", substr('0'x8 .$_[0], -8))) } sub hex2float { unpack("f", pack("H8", substr('0'x8 .$_[0], -8))) } sub hex2double{ unpack("d", pack("H16", substr('0'x16 .$_[0], -16))) } while(){ s/\s+//g; next unless $_; $, = "\t"; print $_, hex2int($_), hex2float($_), hex2double($_), hex2double(fix_endian($_)), "\n"; } __DATA__ 0000 0034 0000 31b1 01 91 403b 8811 bb13 66e4