https://github.com/zgldh/crc16-php
crc16 hash for PHP
https://github.com/zgldh/crc16-php
Last synced: 12 months ago
JSON representation
crc16 hash for PHP
- Host: GitHub
- URL: https://github.com/zgldh/crc16-php
- Owner: zgldh
- License: mit
- Created: 2019-10-18T03:40:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-06-22T05:35:29.000Z (almost 5 years ago)
- Last Synced: 2025-05-14T14:02:29.709Z (about 1 year ago)
- Language: PHP
- Size: 9.77 KB
- Stars: 16
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# crc16-php
crc16 hash methods for PHP
## Usage:
`composer require zgldh/crc16-php`
```
use Crc16\Crc16;
$rawData = '1234567890';
$result = Crc16::IBM($rawData); // dechex($result) === 'c57a'
$result = Crc16::MAXIM($rawData); // dechex($result) === '3a85'
$result = Crc16::USB($rawData); // dechex($result) === '3df5'
$result = Crc16::MODBUS($rawData); // dechex($result) === 'c20a'
$result = Crc16::CCITT($rawData); // dechex($result) === '286b'
$result = Crc16::CCITT_FALSE($rawData); // dechex($result) === '3218'
$result = Crc16::X25($rawData); // dechex($result) === '4b13'
$result = Crc16::XMODEM($rawData); // dechex($result) === 'd321'
$result = Crc16::DNP($rawData); // dechex($result) === 'bc1b'
```
提示: `$rawData` 可以是任意二进制数据,**不要**预先转换成十六进制字符串。
`$result` 是原始整数结果,想得到16进制字符串结果请使用 `dechex` 函数进行转换。
## Test
`composer run-script test`
## Thanks
Thanks for the algorithm author of https://blog.csdn.net/zhang197093/article/details/89061957