PHP CRC16 校正碼的演算法怎麼使用

來源:互聯網
上載者:User
PHP CRC16 校正碼的演算法如何使用
最近用到CRC16,

我現在就是要把 010301180001 算出CRC16的校正碼,通過其他工具,可以得到 校正碼是 05F1

最後完整的代碼就是 01030118000105F1



我現在需要用php程式,寫個函數,來計算這個 05F1 , 網上很難找到 php語言中的CRC16 應用執行個體,昨晚發現php.net官方有這樣一個介紹。
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;}?>


以上的官方的例子, 我怎麼把 010301180001 替換到$test裡去, 到底是要先轉成什嗎?

請高手幫我把這個 010301180001 應用一下,怎麼得出 05F1

謝謝!




------解決方案--------------------
經測試,#1 的代碼符合你的要求

測試代碼
PHP code
$s = pack('H*', '010301180001');$t = crc16(s);printf('=%02x%02x', $t%256, floor($t/256));
------解決方案--------------------
$cs=sprintf('=%02x%02x', $t%256, floor($t/256));
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.