Binary to Text Converter
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
background-color: #f4f7fa;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
width: 100%;
max-width: 600px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
padding: 30px;
text-align: center;
}
.header h1 {
font-size: 2em;
color: #3498db;
}
.header p {
font-size: 1.2em;
color: #7f8c8d;
margin-top: 10px;
}
.converter-box {
margin-top: 30px;
}
.input-area, .output-area {
margin-bottom: 20px;
}
label {
font-size: 1.1em;
color: #2c3e50;
text-align: left;
display: block;
}
textarea {
width: 100%;
padding: 10px;
font-size: 1.1em;
border: 1px solid #bdc3c7;
border-radius: 5px;
outline: none;
resize: vertical;
}
textarea:focus {
border-color: #3498db;
}
.convert-btn {
background-color: #3498db;
color: #fff;
padding: 12px 20px;
font-size: 1.2em;
border: none;
border-radius: 5px;
cursor: pointer;
width: 100%;
margin-top: 10px;
transition: background-color 0.3s ease;
}
.convert-btn:hover {
background-color: #2980b9;
}
.footer {
margin-top: 30px;
font-size: 0.9em;
color: #7f8c8d;
}
@media (max-width: 768px) {
.container {
padding: 20px;
}
.header h1 {
font-size: 1.5em;
}
.header p {
font-size: 1em;
}
.convert-btn {
font-size: 1em;
}
}
function convertBinaryToText() {
const binaryInput = document.getElementById('binaryInput').value.trim();
const textOutput = document.getElementById('textOutput');
if (binaryInput === "") {
textOutput.value = "Please enter binary code.";
return;
}
// Split the input by spaces to get each binary character
const binaryArray = binaryInput.split(" ");
let textResult = '';
// Loop through each binary string and convert to text
for (let i = 0; i < binaryArray.length; i++) {
let charCode = parseInt(binaryArray[i], 2); // Convert binary to decimal
if (isNaN(charCode)) {
textOutput.value = "Invalid binary code!";
return;
}
textResult += String.fromCharCode(charCode); // Convert decimal to text
}
textOutput.value = textResult;
}