Solved

Can crc32() ever return a 5 digit number?

Posted on 2008-06-19
3
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 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