websmoken Posted March 13, 2007 Share Posted March 13, 2007 Howdy guys, I'm trying to add the uniqid() base 16, to a large (15 - 18 bit) base 10 number, store both, later retrieving both numbers and subtracting. Is this possible to do without the results going into scientific notation? Websmoken Link to comment https://forums.phpfreaks.com/topic/42526-solved-math-on-large-base-10-16-unsigned-numbers/ Share on other sites More sharing options...
kenrbnsn Posted March 13, 2007 Share Posted March 13, 2007 Please post the code you're using between [/nocode] tags. Ken Link to comment https://forums.phpfreaks.com/topic/42526-solved-math-on-large-base-10-16-unsigned-numbers/#findComment-206328 Share on other sites More sharing options...
websmoken Posted March 13, 2007 Author Share Posted March 13, 2007 Ken Without posting the 3rd party script, heres what I got. Orig_Num & HexNum is from the script. I added the other code. <?php $HexNum = "0"; $NewNum = "0"; $Orig_Num = "1234567890123456";//any 15-18 bit base 10 number (always positive) from script. $HexNum = uniqid("");// This $HexNum is from script as well (pulled from database). $MidDec = base_convert($HexNum,16,10); $NewNum = $NewNum + ($NewNum + $MidDec);//Store This number back in database. ?> I do the reverse to obtain Original Number: <?php /* $NewNum retrieved from database then $Mid_Dec is subtracted from it, giving you the original number. */ $Orig_Num = "0"; $Mid_Dec = "0"; $Mid_Dec = base_convert($HexNum,16,10);//$HexNum retrieved from database. $Orig_Num = $NewNum - $Mid_Dec; ?> Hope this helps. What I have works its just in scientific notation before it goes in database and after its retrived. Websmoken (Dave) Link to comment https://forums.phpfreaks.com/topic/42526-solved-math-on-large-base-10-16-unsigned-numbers/#findComment-206669 Share on other sites More sharing options...
kenrbnsn Posted March 14, 2007 Share Posted March 14, 2007 After much experimenting, here's what I've come up with... <?php $HexNum = "0"; $NewNum = "0"; $Orig_Num = "1234567890123456";//any 15-18 bit base 10 number (always positive) from script. $HexNum = uniqid("");// This $HexNum is from script as well (pulled from database). $MidDec = base_convert($HexNum,16,10); $NewNum = $NewNum + ($NewNum + $MidDec); // // the next lines are my solution // ob_start(); var_dump($NewNum); $x = ob_get_clean(); $NewNum = str_replace('float(','',str_replace(')','',$x)); //Store This number back in database. ?> Do something similar in the other code snippet. Ken Link to comment https://forums.phpfreaks.com/topic/42526-solved-math-on-large-base-10-16-unsigned-numbers/#findComment-206699 Share on other sites More sharing options...
websmoken Posted March 14, 2007 Author Share Posted March 14, 2007 Ken I tried the code sniplet you provided, a huge THANKS by the way for your help. I then input the number "4444444444444444", in the database was the number "5675336579130000". The output that appeared when I tried to retrieve the number was "4444444444440000". Something with the first sniplet on the input side must somehow be rounding off the 1st 4 LSB's. The hexnum was 45f7d6871e84b. The 3rd party program is for PHP version 4.3.11 & MySQL version 4.0. I'm running PHP5 & MySQL4 on localhost. Don't know it this helps or not. Thanks again, Dave Link to comment https://forums.phpfreaks.com/topic/42526-solved-math-on-large-base-10-16-unsigned-numbers/#findComment-207141 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.