note 93797 modified in function.crc32 by thiago
| From: | thiago@php.net | Date: | Wed, 30 Sep 2009 03:50:29 +0000 |
| Subject: | note 93797 modified in function.crc32 by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161161@lists.php.net to get a copy of this message | ||
For those who want a more familiar return value for the function:
<?php
function strcrc32($text) {
$crc = crc32($text);
if ($crc & 0x80000000) {
$crc ^= 0xffffffff;
$crc += 1;
$crc = -$crc;
}
return $crc;
}
?>
And to show the result in Hex string:
<?php
function int32_to_hex($value) {
$value &= 0xffffffff;
return str_pad(strtoupper(dechex($value)), 8, "0", STR_PAD_LEFT);
}
?>
--was--
For those who want a more familiar return value for the function:
function strcrc32($text) {
$crc = crc32($text);
if ($crc & 0x80000000) {
$crc ^= 0xffffffff;
$crc += 1;
$crc = -$crc;
}
return $crc;
}
And to show the result in Hex string:
function int32_to_hex($value) {
$value &= 0xffffffff;
return str_pad(strtoupper(dechex($value)), 8, "0", STR_PAD_LEFT);
}
http://php.net/manual/en/function.crc32.php