-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinarytask.php
More file actions
40 lines (37 loc) · 1008 Bytes
/
Copy pathbinarytask.php
File metadata and controls
40 lines (37 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html>
<head>
<title>Binary Task</title>
<style>
body{background-color:#C0C0C0;}
form {width: 300px; margin: auto; padding-top: 100px;}
input {padding: 8px 3px; width: 100%; }
#button {width: 70%; margin-left:60px; background-color:#808080;}
</style>
</head>
<body>
<?php
//Converting Decimal to Binary
function convert_decimal($dec){
$binary;
while($dec >= 1){
$rem = $dec % 2;
$dec /= 2;
$binary = $rem.$binary;
}
if($binary == null){
$binary = 0;
}
return $binary;
}
?>
<form method="post">
<input type="number" name="num" placeholder="enter the number" required><br><br>
<input value="<?php $dec = 0;
if(isset($_POST['submit'])) {
$dec = $_POST['num'];
echo convert_decimal($dec);}?>" readonly><br><br>
<input type="submit" name="submit" id="button" value="submit">
</form>
</body>
</html>