binary translator

This commit is contained in:
zyqunix 2025-04-17 12:25:37 +02:00
parent 6e7169a1c0
commit c6e1b4717e
No known key found for this signature in database
GPG key ID: 134A8DEEA83B80E6
3 changed files with 73 additions and 0 deletions

19
binary/index.js Normal file
View file

@ -0,0 +1,19 @@
const binaryElem = document.getElementById('translate-to-binary');
const textElem = document.getElementById('translate-to-text');
binaryElem.addEventListener("click", () => {
const text = document.getElementById("textInput").value;
const binary = text.split("").map(char => {
return char.charCodeAt(0).toString(2).padStart(8, "0");
}).join(" ");
document.getElementById("binaryOutput").value = binary;
});
textElem.addEventListener("click", () => {
const binary = document.getElementById("binaryOutput").value;
const text = binary.split(" ").map(bin => {
return String.fromCharCode(parseInt(bin, 2));
}).join("");
document.getElementById("textInput").value = text;
});