Jump to content

NEED HELP on Easy PHP coding


PHPfreak12

Recommended Posts

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

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

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,

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.