Solved

Can crc32() ever return a 5 digit number?

Posted on 2008-06-19
3
388 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

729 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