How the PHP CRC16 check code algorithm is used
Recently used in the CRC16,
I am now going to calculate the 010301180001 CRC16 check code, through other tools, you can get the check code is 05F1
The final complete code is
01030118000105f1
I now need to use PHP program, write a function, to calculate this 05f1, online difficult to find the PHP language CRC16 application example, last night found Php.net official has such an introduction.
http://cn.php.net/manual/en/function.crc32.php
PHP Code
I made this code to verify transmition with Vantage Pro2 (weather station) based on Crc16-ccitt standard.
>8) ^ ord ($ptr [$i])] ^ (($CRC <<8) & 0X00FFFF); return $CRC;}? >
The official example above, how can I replace 010301180001 to $test, in the end is to turn into what?
Please help me to apply this 010301180001, how to draw 05f1
Thank you!
------Solution--------------------
Tested, #1 code fits your requirements
Test code
PHP Code
$s = pack (' h* ', ' 010301180001 '); $t = CRC16 (s);p rintf (' =%02x%02x ', $t%256, Floor ($t/256));
------Solution--------------------
$cs =sprintf (' =%02x%02x ', $t%256, Floor ($t/256));