sub crc16 { my($crc) = @_; my $length = length($crc); $crc = pack("H$length", $crc); $ctx = Digest::CRC->new(type => "crc16"); $ctx->add($crc); $ctx = Digest::CRC->new(width => 16, init => 0xFFFF,   xorout => 0x0000, poly => 0x8005, refin => 1, refout => 1); $ctx->add($crc); my @crc = split //,$ctx->hexdigest; my $crc = join "",@crc[2,3,0,1]; return $crc; }