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
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

Link to comment
Share on other sites

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 by dalecosp
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.