note 104202 deleted from function.crc32 by danbrown
| From: | danbrown@php.net | Date: | Tue, 31 May 2011 19:05:38 +0000 |
| Subject: | note 104202 deleted from function.crc32 by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180142@lists.php.net to get a copy of this message | ||
Note Submitter: Reikaze
----
I would like to expand a little bit of information about the code "lenar at city dot ee
27-Oct-2008 08:25" mentioned.
About:
Optimized CRC16-CCITT (0xFFFF) Code.
It doesn't returns a hex expressed CRC16-CCITT, instead, returns a decimal integrer.
The result to be used, as part of a string to be sended to any device/application that would
interpretate it as HEX code (e.g. part of a device protocol), first you'll need to base convert
it to hex, and code it as binary hex data.
function INTtorawHEX ( $integrer ) {
$hex = base_convert($integrer, 10, 16);
$rawhex = pack("H*", $hex);
return $rawhex;}
function crc16($data)
{
$crc = 0xFFFF;
for ($i = 0; $i < strlen($data); $i++)
{
$x = (($crc >> 8) ^ ord($data[$i])) & 0xFF;
$x ^= $x >> 4;
$crc = (($crc << 8) ^ ($x << 12) ^ ($x << 5) ^ $x) & 0xFFFF;
}
$crc = INTtorawHEX($crc);
return $crc;
}