mirror of
https://github.com/zyqunix/tools.git
synced 2025-07-06 06:20:30 +02:00
binary translator
This commit is contained in:
parent
6e7169a1c0
commit
c6e1b4717e
3 changed files with 73 additions and 0 deletions
19
binary/index.js
Normal file
19
binary/index.js
Normal 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;
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue