Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

PHP program to convert decimal number into binary with form and database

PHP program to convert a decimal number into binary with form and database

In this tutorial, we will learn about the followings.

  1. PHP program to convert a decimal number into binary
  2. PHP program to convert a decimal number into binary with form 
  3. PHP program to convert a decimal number into binary with database

PHP program to convert a decimal number into binary

In this example, programmer stores the values in the variables. However, if you interested to see the program about taking values in the form, please see example 2.

<?php
 $number=10; $mor=0;
echo"Dacimal Number is = $number<br>";
$mor=decbin($number);
echo"Binary Number is = $mor";
?>

PHP program to convert a decimal number into binary with form

In this example, we will take the inputs from the user and store them in variables.

<html>
<head>
<title></title>
   
</head>
<body>
                     <div class="nukr"><h2 class="col_insert" >Reverse Number</h2></div>
                     <form action="" method="post" name="insert_form" id="insert_form" class="comment-form">
                     <table class="tableI1" align="left" border="0" bordercolor="#FFFFFF" >
                     <tr><td ><b><i>Enter Number</b></i></td>
                     <td><input id="number" name="number" type="text" size="30" /> 
                     <tr><td></td><td><input type="submit" id="btnsubmit" name="btnsubmit" value="Calculate" size="30"/></td></tr>
                     <tr><td></td><td>       </td></tr>
                     </table>
                      </form>

</body>
</html>
<?php
if(isset($_POST['btnsubmit']))
{

 $number ;$mor=0;
$number=$_POST['number'];
echo"Dacimal Number is = $number<br>";
$mor=decbin($number);

echo"Binary Number is = $mor";

}
?>

PHP program to convert a decimal number into binary with database

In this example, we will take the inputs from the user and temporarily store them in variables and then finally stores them permanently in the database.

<html>
<head>
<title></title>
   
</head>

<body>

                     <div class="nukr"><h2 class="col_insert" >Covert a  Number from decimal to binary</h2></div>
                     <form  method="post">
                     <table class="tableI1" align="left" border="0" bordercolor="#FFFFFF" >
                     <tr><td ><b><i>Enter Number</b></i></td>
                     <td><input id="number" name="number" type="text" size="30" /> 
                     <tr><td></td><td><input type="submit" id="btnsubmit" name="btnsubmit" value="Calculate" size="30"/></td></tr>
                     <tr><td></td><td>       </td></tr>
                     </table>
                      </form>

</body>
</html>
<?php
//include 'dbconction.php';
?>
<?php
$conn= mysqli_connect('localhost','root','','test');
if(isset($_POST['btnsubmit']))
{
$number=$_POST['number'];
$rs=$number;
$mor=0;
echo"Dacimal Number is = $rs<br>";
$mor=decbin($number);
echo"Binary Number is = $mor";
$sql= "insert into  reves(Numbe, Revers) Value ('$rs','$mor')";
   if($conn->query($sql)=== TRUE)
{
	echo"<font color=#FF00FF> New Record Inserted<br></font>";
	}
  else
  {
	  echo"Error:".$sql."<br>".$conn->error;
	  }	
}
?>

Database to convert decimal number into binary

decimal to binary conversion php database

Figure: decimal to binary conversion php database

Prof. Fzal Rehman Shamil
Instructor, Researcher, Blogger, SEO Expert, Poet and Publisher of International Journal Of Software, Technology & Science ISSN : 2616 - 5325