PHP CRC16 Check code algorithm how to use

Source: Internet
Author: User
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));
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.