reneeshtk Posted October 6, 2007 Share Posted October 6, 2007 I have to convert a hexa decimal value to a double value in php. I have converted hexadecimal to integer..using function base_convert(). But in this case it not giving me a good result.. Examples: 9A99999999193A40 = 26.1 (Approx) CDCCCCCCCC4C3CC0 = -28.3 (Approx) In this the order may be from back to front. ie..403A19999999999A.. If you have any idea please help. Quote Link to comment https://forums.phpfreaks.com/topic/72066-converting-a-hexadecimal-value-to-an-equivaluent-decimalneed-help/ Share on other sites More sharing options...
heckenschutze Posted October 6, 2007 Share Posted October 6, 2007 hexdec() perhaps? http://php.net/manual/en/function.hexdec.php Quote Link to comment https://forums.phpfreaks.com/topic/72066-converting-a-hexadecimal-value-to-an-equivaluent-decimalneed-help/#findComment-363135 Share on other sites More sharing options...
reneeshtk Posted October 6, 2007 Author Share Posted October 6, 2007 I have to convert a hexa decimal value to a double value in php. I have converted hexadecimal to integer..using function base_convert(). But in this case it not giving me a good result.. Examples: 9A99999999193A40 = 26.1 (Approx) CDCCCCCCCC4C3CC0 = -28.3 (Approx) In this the order may be from back to front. ie..403A19999999999A.. If you have any idea please help. hexdec() ....it will not return the required result Quote Link to comment https://forums.phpfreaks.com/topic/72066-converting-a-hexadecimal-value-to-an-equivaluent-decimalneed-help/#findComment-363144 Share on other sites More sharing options...
darkfreaks Posted October 6, 2007 Share Posted October 6, 2007 can you post your code please? Quote Link to comment https://forums.phpfreaks.com/topic/72066-converting-a-hexadecimal-value-to-an-equivaluent-decimalneed-help/#findComment-363155 Share on other sites More sharing options...
darkfreaks Posted October 6, 2007 Share Posted October 6, 2007 <?php $hex = "9A99999999193A40"; echo hexdec($hex);?> Quote Link to comment https://forums.phpfreaks.com/topic/72066-converting-a-hexadecimal-value-to-an-equivaluent-decimalneed-help/#findComment-363158 Share on other sites More sharing options...
reneeshtk Posted October 6, 2007 Author Share Posted October 6, 2007 I have to convert a hexa decimal value to a double value in php. I have converted hexadecimal to integer..using function base_convert(). But in this case it not giving me a good result.. Examples: 9A99999999193A40 = 26.1 (Approx) CDCCCCCCCC4C3CC0 = -28.3 (Approx) In this the order may be from back to front. ie..403A19999999999A.. If you have any idea please help. I have converted a integer type hex value by using the follwing code $dat=801A0600 $rst=change_to_int($dat); echo $rst; //It will show 40000...This is the result here I need function change_to_int($dat){ $chr_data=""; for($i=strlen($dat);$i>0;$i=$i-2){ $datac=substr($dat,$i-2,2); $chr_data.=$datac; } return base_convert($chr_data,16,10); } But this is not working in the case of double type values...so please give an idea. Quote Link to comment https://forums.phpfreaks.com/topic/72066-converting-a-hexadecimal-value-to-an-equivaluent-decimalneed-help/#findComment-363219 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.