in reply to CRC 16
I can't see how 0x8404 is the 'reverse' of 0x1021 by any stretch of my imagination,(*)
but a simple brute force conversion yields:
#! perl -slw use strict; sub crc16 { use constant POLY => 0x8408; my $crc = 0; for my $c ( unpack 'C*', $_[0] ) { $crc ^= $c; for my $b ( 0 .. 7 ) { my $carry = $crc & 1; $crc >>= 1; if( $carry ) { $crc ^= POLY; } } } return $crc; } my $data = "\x64\x01"; printf "crc: %04x\n", crc16( $data ); __END__ C:\test>997760.pl crc: 13bc
Which works for the (inadequate, single) sample data.
(* 0x1021 -> 0001_0000_0010_0001 bitwise reversed -> 1000_0100_0000_1000 -> 0x8408 )
|
|---|