Create a PHP program that can input decimal then convert it binary, octal, hexadecimal using functions and arrays. Reminder: Do not use built-in functions for the conversion.
Create a PHP program that can input decimal then convert it binary, octal, hexadecimal using functions and arrays.
Reminder: Do not use built-in functions for the conversion.
MY CODE:
<!DOCTYPE html>
<html>
<body>
<title> Act </title>
<table>
<form action="Act.php" method="POST">
<td> Enter Decimal: </td>
<td><input type="text" name="amount" value="<?=isset($_POST['amount'])?$_POST['amount']:''?>"></td>
<td><input type="submit" value="Generate"></td>
</form>
<?php
if(isset($_POST['amount'])){
function dToB($n)
{
$amount;
$binaryNo;
$i = 0;
while($n > 0)
{
$binaryNo[$i] = $n % 2;
$n = (int) ($n / 2);
$i++;
}
for($j = $i - 1 ;$j >= 0; $j--)
echo $binaryNo[$j];
return $amount;
}
}
?>
<tr>
<td><b> Binary: </b></td>
<td> <input type="text" value="<?=isset($$amount)?$$amount: ''?>" readonly> </td>
</tr>
</table>
</html>
</body>
Step by step
Solved in 2 steps with 1 images