-
Notifications
You must be signed in to change notification settings - Fork 0
/
ascii-to-binary.html
88 lines (66 loc) · 1.92 KB
/
ascii-to-binary.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: flex;
flex-direction: column;
align-items: center;
}
input[type="text"] {
font-size: 18px;
padding: 10px;
margin: 10px;
width: 70%;
}
button {
padding: 10px 20px;
font-size: 18px;
margin-top: 20px;
background-color: lightblue;
border: none;
border-radius: 5px;
cursor: pointer;
}
textarea {
font-size: 18px;
padding: 10px;
margin: 10px;
width: 70%;
font-family: Arial, Helvetica, sans-serif;
}
#swapimg {
transform: rotate(90deg);
}
</style>
</head>
<body>
<div class="container">
<h2>ASCII to Binary Converter</h2>
<input type="text" id="ascii-input">
<div>
<button id="convert-button">Convert</button>
<button onclick="swap()" id="convert-button"><img id="swapimg" width="15" src="Image/arrows.png" alt=""
srcset=""> Swap</button>
</div>
<input type="text" id="binary-output" hidden>
<textarea id="text" cols="30" rows="10" disabled></textarea>
</div>
<script>
const convertButton = document.querySelector("#convert-button");
convertButton.addEventListener("click", function () {
const asciiInput = document.querySelector("#ascii-input");
const binaryOutput = document.querySelector("#binary-output");
const binarytext = document.querySelector("#text");
binaryOutput.value = "";
for (let i = 0; i < asciiInput.value.length; i++) {
binaryOutput.value += asciiInput.value[i].charCodeAt(0).toString(2) + " ";
}
binarytext.value = binaryOutput.value;
});
const swap = () => {
window.location.href = "binary-to-ascii.html";
}
</script>
</body>
</html>