Jump to content


Photo

change negative number to positive or unsigned


  • Please log in to reply
3 replies to this topic

#1 swcarrel

swcarrel
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 02 May 2006 - 10:50 PM

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...


#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 02 May 2006 - 11:20 PM

Hmmm, how about
$x = (-1);  // negative 1

$y = 123456; // another negative number

$y = $y * $x;
viola

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 02 May 2006 - 11:30 PM

<?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;
}
?>

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 swcarrel

swcarrel
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 02 May 2006 - 11:50 PM

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

$y = 123456; // another negative number

$y = $y * $x;
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) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hmmm, how about
$x = (-1);  // negative 1

$y = 123456; // another negative number

$y = $y * $x;
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) View Post[/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) View Post[/div][div class=\'quotemain\'][!--quotec--]
<?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;
}
?>
[/quote]

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users