PHPfreak12 Posted November 15, 2013 Share Posted November 15, 2013 I am on the first year at college studying computer science and they sent me to write a php program that can change a decimal number to IEEE754 standard on 16bits. I know most of you will laugh because it is very easy but I need help. this is what i got so far. ALL i need is how to control the mantissa.. you know, save 10 numbers.. and how to control the while loop so he stops when i have 10 spots on mantissa.. <?php echo "Enter any number\n"; $number=trim(fgets(STDIN)); $low=floor($number); $decimal=$number - $low; $real=decbin($low); while(0<$decimal<1) { $mantissa[]=$decimal*2; } echo "\n"; ?> Link to comment https://forums.phpfreaks.com/topic/283940-need-help-on-easy-php-coding/ Share on other sites More sharing options...
dalecosp Posted November 15, 2013 Share Posted November 15, 2013 Set a counter variable, increment it in the while loop, and either check it with logical AND in the conditional or use a break() statement inside an "if" in the while loop? Link to comment https://forums.phpfreaks.com/topic/283940-need-help-on-easy-php-coding/#findComment-1458460 Share on other sites More sharing options...
PHPfreak12 Posted November 16, 2013 Author Share Posted November 16, 2013 Set a counter variable, increment it in the while loop, and either check it with logical AND in the conditional or use a break() statement inside an "if" in the while loop? thank you very much for responding. but can you be more detailed? don't respond if I am asking too much. thanks Link to comment https://forums.phpfreaks.com/topic/283940-need-help-on-easy-php-coding/#findComment-1458504 Share on other sites More sharing options...
dalecosp Posted November 16, 2013 Share Posted November 16, 2013 Won't you get in trouble if I do your homework for ya? ;) <?php echo "Enter any number\n";$number=trim(fgets(STDIN));$low=floor($number);$decimal=$number - $low;$real=decbin($low); $counter = 0; while(0<$decimal<1) { //fixed this; either way works in PHP, but Javascript needs //the bracket on the right --- so it's a good habit to start $mantissa[]=$decimal*2; $counter++; if ($counter == 10) { break; }} echo "\n";?> HTH, Link to comment https://forums.phpfreaks.com/topic/283940-need-help-on-easy-php-coding/#findComment-1458506 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.