use strict; use warnings; while () { my ($hb, $lb) = split /\s+/; print "$hb $lb -> " . decode_d2b($hb, $lb) . "\n"; } sub decode_d2b { my $hb = hex($_[0]); my $lb = hex($_[1]); if ($hb & 0x80) { return -( (~$hb & 255) + ((~$lb & 255) + 1)/256 ); } else { return $hb + $lb/256; } } __DATA__ 00 00 -> 0 00 01 -> 1/256 FF FF -> -1/256 FF F0 -> -1 80 00 -> -128 80 01 -> -127,996 7F FF -> 127,996