Solved

Can crc32() ever return a 5 digit number?

Posted on 2008-06-19
3
376 Views
Last Modified: 2008-06-19
From all my tests crc32 always generates a 9 digit number that is either positive or negative.

         <?php
         echo crc32("Hello"); //// Returns  -137262718
         ?>

But could crc32 ever return a 5 or 10 digit number, or a number that began with 0 like 007262718 ?
0
Comment
Question by:hankknight
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 300 total points
ID: 21822977
It can return any value that can be represented by a 32 bit value.

Which value you get depends on how you interpret the value. You interpret it as a signed integer, so the values you can get are any value between -2147483648 and 2147483647
0
 
LVL 2

Assisted Solution

by:kszurek
kszurek earned 200 total points
ID: 21822990

<?PHP
function x($a)
{
	$b = abs(crc32($a));
	$strlen = 10-strlen($b);
	$b = str_repeat(0, $strlen).$b;
	return $b;
}
echo x("Hello");
?>

Open in new window

0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21823004
Note that a CRC32 value is usually shown in hexadecimal.

So, instead of -137262718 for example, you'd show :  F7D18982
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question