Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pogrema
PHP_1
Commits
cba12c78
Commit
cba12c78
authored
2 years ago
by
pogrema
Browse files
Options
Download
Email Patches
Plain Diff
Commit
parent
1aba05a3
master
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
convertor.php
+38
-0
convertor.php
index.php
+33
-0
index.php
style.css
+41
-0
style.css
with
112 additions
and
0 deletions
+112
-0
convertor.php
0 → 100644
+
38
-
0
View file @
cba12c78
<?php
function
convertor
(
$num
,
$set
,
$submit
)
{
if
(
isset
(
$submit
))
{
if
(
$set
==
'decimalToBinary'
||
$set
==
'binaryToDecimal'
)
{
if
(
$set
==
'decimalToBinary'
)
{
$result
=
$num
;
echo
"<p>Decimal:
$num
</p>"
;
while
(
$num
>
0
)
{
$residue
=
$num
%
2
;
$num
=
floor
(
$num
/
2
);
echo
$num
.
"-"
.
$residue
.
"<br>"
;
}
echo
"<p>Binary: "
.
decbin
(
$result
)
.
"</p>"
;
}
else
{
echo
"<p>Binary:
$num
</p>"
;
$decimal
=
0
;
$num
=
str_split
(
$num
);
$num
=
array_reverse
(
$num
);
foreach
(
$num
as
$key
=>
$digit
)
{
if
(
$digit
==
1
)
{
echo
$digit
.
" 2^"
.
$key
.
" = "
.
pow
(
2
,
$key
)
.
"<br>"
;
}
else
{
echo
$digit
.
" 2^"
.
$key
.
" = "
.
pow
(
0
,
$key
)
.
"<br>"
;
}
}
for
(
$i
=
0
;
$i
<
count
(
$num
);
$i
++
)
{
if
(
$num
[
$i
]
==
1
)
{
$decimal
+=
pow
(
2
,
$i
);
}
}
echo
"<p>Decimal:
$decimal
</p>"
;
}
}
}
}
?>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
index.php
0 → 100644
+
33
-
0
View file @
cba12c78
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<link
rel=
"stylesheet"
href=
"style.css"
>
<title>
Convertor
</title>
</head>
<body>
<form
method=
"post"
class=
"flex"
action=
""
>
<h2>
Type a number
</h2>
<input
class=
"field"
type=
"nuber"
name=
"number"
id=
"inDumber"
>
<select
class=
"field"
name=
"selection"
id=
"idSelection"
>
<option
value=
""
disabled
selected
>
Choose an option
</option>
<option
value=
"decimalToBinary"
>
Decimal To Binary
</option>
<option
value=
"binaryToDecimal"
>
Binary To Decimal
</option>
</select>
<input
class=
"field pointer"
type=
"submit"
name=
"submit"
>
<div
class=
"column field"
>
<?php
require_once
'convertor.php'
;
$num
=
$_POST
[
'number'
];
$set
=
$_POST
[
'selection'
];
$submit
=
$_POST
[
'submit'
];
convertor
(
$num
,
$set
,
$submit
);
?>
</div>
</form>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
style.css
0 → 100644
+
41
-
0
View file @
cba12c78
body
{
display
:
flex
;
justify-content
:
center
;
align-items
:
center
;
background-color
:
rgb
(
228
,
228
,
228
);
}
.flex
{
display
:
flex
;
justify-content
:
center
;
align-items
:
center
;
background-color
:
white
;
padding
:
2rem
;
flex-direction
:
column
;
border-radius
:
1rem
;
margin
:
0
auto
;
}
.field
{
position
:
relative
;
display
:
flex
;
border
:
none
;
outline
:
none
;
justify-content
:
center
;
align-items
:
center
;
background-color
:
rgb
(
228
,
228
,
228
);
border-radius
:
1rem
;
padding
:
0.5rem
;
min-width
:
16rem
;
margin
:
0.5rem
;
}
.column
{
display
:
flex
;
min-height
:
1rem
;
flex-direction
:
column
;
}
.pointer
{
cursor
:
pointer
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets