Skip to content

Instantly share code, notes, and snippets.

@robbinhan
Created March 18, 2012 06:43
Show Gist options
  • Save robbinhan/2069428 to your computer and use it in GitHub Desktop.
Save robbinhan/2069428 to your computer and use it in GitHub Desktop.
php crc32算法
char *p;
int len, nr;
php_uint32 crcinit = 0;
register php_uint32 crc;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &p, &nr) == FAILURE) {
return;
}
crc = crcinit^0xFFFFFFFF;
for (len =+nr; nr--; ++p) {
crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32tab[(crc ^ (*p)) & 0xFF ];
}
RETVAL_LONG(crc^0xFFFFFFFF);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment