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. 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 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 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? 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);?> 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. 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
Archived
This topic is now archived and is closed to further replies.