Tuesday, July 29, 2014

Decimal to binary conversion program in php

the following code will do the conversion of decimal to binary.....no error has been occured

<html>
<body>
<form method="POST" action="deci.php">
<input type="text" name="t1" placeholder="enter a value here">
<br>
<br>
<input type="submit" value="find" name="submit">
</form>
<?php
$sum="";
if(isset($_POST['submit']))
{
$val=$_POST['t1'];
$n=$val;
while($n!=0)
{
 $rem=$n%2;
 $sum.=$rem;
 $quot=$n/2;
 $n=floor($quot);
 
}


echo strrev($sum);

}
?>
</body>
</html>

No comments:

Post a Comment