forked from patdryburgh/hitchens
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary.html
More file actions
45 lines (44 loc) · 1.42 KB
/
binary.html
File metadata and controls
45 lines (44 loc) · 1.42 KB
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
41
42
43
44
45
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mr Lee's lesson</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
input {
padding: 10px;
font-size: 18px;
margin-bottom: 20px;
}
.output {
font-size: 20px;
font-weight: bold;
}
</style>
</head>
<body>
<h2>Mr Lee's lesson</h2>
<input type="number" id="decimalInput" placeholder="Enter a decimal number" oninput="convertNumber()">
<div class="output" id="binaryOutput"></div>
<div class="output" id="hexOutput"></div>
<script>
function convertNumber() {
let decimal = document.getElementById("decimalInput").value;
if (decimal === "") {
document.getElementById("binaryOutput").innerText = "";
document.getElementById("hexOutput").innerText = "";
return;
}
let binary = parseInt(decimal, 10).toString(2);
let hex = parseInt(decimal, 10).toString(16).toUpperCase();
document.getElementById("binaryOutput").innerText = `Binary: ${binary}`;
document.getElementById("hexOutput").innerText = `Hexadecimal: ${hex}`;
}
</script>
</body>
</html>