# argument: short integer to convert to two bytes # return: two bytes sub short_to_bytes { local @_ = unpack("C*",pack("L",shift)); (shift, shift); } # argument: two bytes to convert into an integer # return: short integer sub bytes_to_short { my $res = 0; $res |= $bytes[1] & 0xFF; $res <<= 8; $res |= $bytes[0] & 0xFF; return $res; }