note 83691 added to function.crc32

From: Date: Sat, 07 Jun 2008 23:14:29 +0000
Subject: note 83691 added to function.crc32
Groups: php.notes 
Request: Send a blank email to php-notes+get-140217@lists.php.net to get a copy of this message
I tried to use this function to calculate CRC32 values that are compatible with the CRCs in the well known SFV files. Apparently, this doesn't work out of the box, since the crc32 hash algo calculates a different value than found in SFV files (probably a different poly is used). There is another hash algo supported by PHP though, crc32b, which is almost right, but needs some transformation. The transformation involves a signed-unsigned conversion and a byte order (or endian) swap. Below is my simple function for the task. <? function crc32_file($fileName) { $crc = hash_file("crc32b", $fileName); $crc = sprintf("%08x", 0x100000000 + hexdec($crc)); return substr($crc, 6, 2) . substr($crc, 4, 2) . substr($crc, 2, 2) . substr($crc, 0, 2); } ?> As a side note: <? crc32(file_get_contents("some_filename.dat")); ?> produces correct output without additional transformation. I wonder if this is a bug of PHP5 i should try to report. ---- Server IP: 217.20.138.73 Probable Submitter: 213.253.208.42 ---- Manual Page -- http://www.php.net/manual/en/function.crc32.php Edit -- https://master.php.net/note/edit/83691 Del: integrated -- https://master.php.net/note/delete/83691/integrated Del: useless -- https://master.php.net/note/delete/83691/useless Del: bad code -- https://master.php.net/note/delete/83691/bad+code Del: spam -- https://master.php.net/note/delete/83691/spam Del: non-english -- https://master.php.net/note/delete/83691/non-english Del: in docs -- https://master.php.net/note/delete/83691/in+docs Del: other reasons-- https://master.php.net/note/delete/83691 Reject -- https://master.php.net/note/reject/83691 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140217) next »