note 28012 modified in function.crc32 by jmcastagnetto
| From: | jmcastagnetto@php.net | Date: | Sun, 29 Dec 2002 22:43:59 +0000 |
| Subject: | note 28012 modified in function.crc32 by jmcastagnetto | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-41439@lists.php.net to get a copy of this message | ||
Here is a tested and working CRC16-Algorithm:
function crc16($string) {
$crc = 0xFFFF;
for ($x = 0; $x < strlen ($string); $x++) {
$crc = $crc ^ ord($string[$x]);
for ($y = 0; $y < 8; $y++) {
if (($crc & 0x0001) == 0x0001) {
$crc = (($crc >> 1) ^ 0xA001);
} else { $crc = $crc >> 1; }
}
}
return $crc;
}
Regards,
Mario
--was--
Why do you post non-working and somehow bogus-looking code, Martin? It also didn't work for me
and it is not the Standard-CRC16-Algorithm ... anyway ... here is a tested and working
CRC16-Algorithm:
function crc16($string) {
$crc = 0xFFFF;
for ($x = 0; $x < strlen ($string); $x++) {
$crc = $crc ^ ord($string[$x]);
for ($y = 0; $y < 8; $y++) {
if (($crc & 0x0001) == 0x0001) {
$crc = (($crc >> 1) ^ 0xA001);
} else { $crc = $crc >> 1; }
}
}
return $crc;
}
Regards,
Mario
http://www.php.net/manual/en/function.crc32.php