note 28012 modified in function.crc32 by vrana

From: Date: Tue, 17 Aug 2004 14:55:53 +0000
Subject: note 28012 modified in function.crc32 by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79807@lists.php.net to get a copy of this message
Here is a tested and working CRC16-Algorithm: <?php 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-- 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://php.net/manual/en/function.crc32.php

« previous php.notes (#79807) next »