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"; ?> Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
dalecosp Posted November 16, 2013 Share Posted November 16, 2013 (edited) 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, Edited November 16, 2013 by dalecosp Quote Link to comment 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.