Initial commit

This commit is contained in:
Robert Miles 2019-07-27 03:42:00 -04:00
commit 00b36575d0
3 changed files with 88 additions and 0 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# Number
A simple setup for gathering number conversions between setups.

27
index.php Normal file
View File

@ -0,0 +1,27 @@
<?php
if(array_key_exists("type",$_GET)) {
include "number.php";
die();
}
?>
<html>
<head>
<title>Number - info for numbers.</title>
<link rel="stylesheet" href="https://tilde.team/css/hacker.css">
</head>
<body><div class="container">
<h1>Number</h1>
<p>Get info on a number:</p>
<form action="./" method="GET">
<div type="form-group">
<p>Label Type:</p>
<div type="form-check"><input class="form-check-input" id="type-dec" type="radio" name="type" value="dec"><label for="type-dec">Decimal</label></div>
<div type="form-check"><input class="form-check-input" id="type-hex" type="radio" name="type" value="hex"><label for="type-dec">Hexadecimal</label></div>
</div>
<div type="form-group">
<label for="number">Number: </label><input class="form-control" type="text" name="number" id="number">
</div>
<button type="submit" class="btn btn-primary">Check it out!</button>
</form>
</div></body>
</html>

58
number.php Normal file
View File

@ -0,0 +1,58 @@
<?php
$type = $_GET["type"];
$number = $_GET["number"];
if ($type=="hex") {
$number = base_convert($number,16,10);
$number_hex = base_convert($number,10,16);
} else {
$number_hex = base_convert($number,10,16);
}
if (array_key_exists("format",$_GET)) { // client wants a custom response
if ($_GET["format"]=="json") { // JSON response
header("Content-Type: application/json; UTF-8"); // we're responding with JSON
echo json_encode(array(
"decimal" => $number+0, // do funky shit so number is always of type `int`
"hex" => $number_hex,
"error" => NULL // no error here! (this is where we might later throw errors for invalid number types)
));
die(); // don't immediately follow this with the HTML page
}
// "We don't do that here."
http_response_code(400);
die("Bad request: format not in 'json'");
}
?>
<html>
<head>
<title>Number - info for numbers.</title>
<link rel="stylesheet" href="https://tilde.team/css/hacker.css">
</head>
<body><div class="container">
<h1>Number</h1>
<h3><?php
if ($type=="hex") {
echo "0x".$number_hex." is decimal ".$number;
} else {
echo "Decimal ".$number." is 0x".$number_hex;
}
?></h3>
<table class="table table-striped">
<thead>
<tr>
<th>System</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Decimal</td>
<td><?=$number?></td>
</tr>
<tr>
<td>Hexadecimal</td>
<td><?="0x".$number_hex?></td>
</tr>
</tbody>
</table>
</div></body>
</html>