-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
50 lines (43 loc) · 1.24 KB
/
script.js
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
let encryptbtn = document.getElementById("encrypt");
let clearbtn = document.getElementById("clear");
/* const clickTest = () => {
alert("Click Test");
}; */
const convert_binary = () => {
let inputbox = document.getElementById("input");
let inputtxt = document.getElementById("input").value;
let outputbox = document.getElementById("output");
let length = inputtxt.length;
const BITS_IN_BYTE = 8;
let byteString = "";
for (let i = 0; i < length; i++) {
let decimal = inputtxt.charCodeAt(i);
let byte = [];
for (let j = BITS_IN_BYTE - 1; j >= 0; j--) {
byte[j] = decimal % 2;
decimal = Math.floor(decimal / 2);
}
// Print the binary representation
byteString += byte.join("");
byteString += " ";
}
outputbox.value = byteString;
inputbox.value = "";
};
//deletes output textbox
const clear_text = () => {
let outputbox = document.getElementById("output");
outputbox.value = "";
};
encryptbtn.addEventListener("click", convert_binary);
clearbtn.addEventListener("click", clear_text);
//prints emoji depending on if it's a 0 or a 1
/* const print_bulb = (bit) => {
if (bit == 0) {
// Dark emoji
print("U000026AB");
} else if (bit == 1) {
// Light emoji
print("U0001F7E1");
}
}; */