How to use the PHPCRC16 verification code algorithm

Source: Internet
Author: User
How to use the CRC16 recently used in the PHPCRC16 verification code algorithm? now I want to calculate the CRC16 verification code by 010301180001. using other tools, the verification code is 05F1. The final complete code is 01030118000105F1. I need to use a php program and write a function to calculate this 05F1 code, on the Internet, it is hard to find out how to use the C php CRC16 checksum algorithm in PHP.
Recently used CRC16,

Now I want to calculate the CRC16 verification code of 010301180001. with other tools, the verification code is 05F1.

The complete code is 01030118000105F1



Now I need to use a php program to write a function to calculate this 05F1. it is difficult to find the CRC16 application instance in php on the internet. Last night I found that php.net has such an official 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;}?>


In the official example above, how can I replace 010301180001 with $ test?

Please help me apply this 010301180001. how can we get 05F1?

Thank you!




------ Solution --------------------
Tested, the #1 code meets your requirements.

Test Code
PHP code
$ S = pack ('H * ', '000000'); $ t = crc16 (s); printf (' = % 02x % 02x', $ t % 010301180001, floor ($ t/256 ));
------ Solution --------------------
$ Cs = sprintf ('= % 02x % 02x', $ t % 256, floor ($ t/256 ));

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.