swcarrel Posted May 2, 2006 Share Posted May 2, 2006 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... Link to comment https://forums.phpfreaks.com/topic/8924-change-negative-number-to-positive-or-unsigned/ Share on other sites More sharing options...
litebearer Posted May 2, 2006 Share Posted May 2, 2006 Hmmm, how about[code]$x = (-1); // negative 1$y = 123456; // another negative number$y = $y * $x;[/code]violaLite... Link to comment https://forums.phpfreaks.com/topic/8924-change-negative-number-to-positive-or-unsigned/#findComment-32805 Share on other sites More sharing options...
.josh Posted May 2, 2006 Share Posted May 2, 2006 [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] Link to comment https://forums.phpfreaks.com/topic/8924-change-negative-number-to-positive-or-unsigned/#findComment-32809 Share on other sites More sharing options...
swcarrel Posted May 2, 2006 Author Share Posted May 2, 2006 [!--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]violaLite...[/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]violaLite...[/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... Link to comment https://forums.phpfreaks.com/topic/8924-change-negative-number-to-positive-or-unsigned/#findComment-32811 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.