_aLfa_

php crc16

Feb 28th, 2012
1,199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.30 KB | None | 0 0
  1. function crc16($string, $crc = 0)
  2. {
  3.     for ($x = 0; $x < strlen($string); $x++)
  4.     {
  5.         $crc = $crc ^ ord($string[$x]);
  6.         for ($y = 0; $y < 8; $y++)
  7.         {
  8.             if (($crc & 0x0001) == 0x0001)
  9.             {
  10.                 $crc = ($crc >> 1) ^ 0xA001;
  11.             }
  12.             else
  13.             {
  14.                 $crc = $crc >> 1;
  15.             }
  16.         }
  17.     }
  18.     return $crc;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment