Jump to content

Archived

This topic is now archived and is closed to further replies.

swcarrel

change negative number to positive or unsigned

Recommended Posts

Generating a unique confirmation number for an order -- using

$Transaction = date("Ymd") . $phone . $name;
$ConfirmationNumber=crc32($Transaction);

This generates a negative number. I want to insert an unsigned number into the MySQL database, and print it on a "thank you" page to the customer.

Be gentle -- I'm a REAL newbie...

Share this post


Link to post
Share on other sites
Hmmm, how about
[code]
$x = (-1);  // negative 1

$y = 123456; // another negative number

$y = $y * $x;[/code]viola

Lite...

Share this post


Link to post
Share on other sites
[code]
<?php
/**
* Function to compute the unsigned crc32 value.
* PHP crc32 function returns int which is signed, so in order to get the correct crc32 value
* we need to convert it to unsigned value.
*
* @param $str - String to compute the unsigned crc32 value.
* @return $var - Unsinged inter value.
*/
function computeUnsignedCRC32($str){
   sscanf(crc32($str), "%u", $var);
   return $var;
}
?>
[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=370747:date=May 2 2006, 05:20 PM:name=litebearer)--][div class=\'quotetop\']QUOTE(litebearer @ May 2 2006, 05:20 PM) [snapback]370747[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hmmm, how about
[code]
$x = (-1);  // negative 1

$y = 123456; // another negative number

$y = $y * $x;[/code]viola

Lite...
[/quote]

Perfect! Works fine. Seems like there should be a harder, more complicated way, though

[!--quoteo(post=370747:date=May 2 2006, 05:20 PM:name=litebearer)--][div class=\'quotetop\']QUOTE(litebearer @ May 2 2006, 05:20 PM) [snapback]370747[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hmmm, how about
[code]
$x = (-1);  // negative 1

$y = 123456; // another negative number

$y = $y * $x;[/code]viola

Lite...
[/quote]


[!--quoteo(post=370753:date=May 2 2006, 05:45 PM:name=samindenver)--][div class=\'quotetop\']QUOTE(samindenver @ May 2 2006, 05:45 PM) [snapback]370753[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Perfect! Works fine. Seems like there should be a harder, more complicated way, though
[/quote]
Thanks, Lite!

[!--quoteo(post=370751:date=May 2 2006, 05:30 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 2 2006, 05:30 PM) [snapback]370751[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]
<?php
/**
* Function to compute the unsigned crc32 value.
* PHP crc32 function returns int which is signed, so in order to get the correct crc32 value
* we need to convert it to unsigned value.
*
* @param $str - String to compute the unsigned crc32 value.
* @return $var - Unsinged inter value.
*/
function computeUnsignedCRC32($str){
   sscanf(crc32($str), "%u", $var);
   return $var;
}
?>
[/code]
[/quote]

Thanks, Cray -- I'll play with this one, too, in case sometimes the value is positive...

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.