-
Notifications
You must be signed in to change notification settings - Fork 1
/
bin2text.html
83 lines (65 loc) · 2.38 KB
/
bin2text.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
<!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">
<title>
Bin to Text
</title>
<!--Bootstrap with its required JS and CSS files with crossorigin and integrity attributes-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.6.1.min.js"
integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<br>
<!-- create a center div to hold the header -->
<div class="row">
<div class="col-md-12">
<h1 class="text-center">Binary to Text</h1>
</div>
</div>
<!-- Bootstrap form for input text -->
<form>
<div class="form-group">
<label for="text">Binary:</label>
<textarea class="form-control" id="text" name="text">
</textarea>
<label for="result">
Text:
</label>
<textarea id="result" class="form-control" readonly>
</textarea>
</div>
<!--Button to copy text to clipboard-->
<button type="button" class="btn btn-primary" id="copy">Copy</button>
</form>
</div>
</body>
<script>
// create a function to convert binary to text
function binaryAgent(str) {
var newBin = str.split(" ");
var binCode = [];
for (i = 0; i < newBin.length; i++) {
binCode.push(String.fromCharCode(parseInt(newBin[i], 2)));
}
return binCode.join("");
}
// add event listener to input change
$("#text").on("input", function () {
var text = $(this).val();
var result = binaryAgent(text.trim());
$("#result").val(String(result.toString()));
});
// add event listener to button click
$("#copy").on("click", function () {
var text = $("#result").val();
var result = binaryAgent(text.trim());
$("#result").val(String(result.toString()));
});
</script>
</html>