Binary to ASCII Converter
/* General Body and Layout Styling */
body {
font-family: 'Poppins', sans-serif;
margin: 0;
padding: 0;
background-color: #f0f8ff;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
box-sizing: border-box;
}
.container {
background: linear-gradient(145deg, #ff6b6b, #f1c40f);
padding: 40px;
border-radius: 10px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
text-align: center;
width: 100%;
max-width: 500px;
}
header {
margin-bottom: 20px;
}
header h1 {
font-size: 2.5rem;
color: white;
margin: 0;
}
header p {
color: #fff;
font-size: 1rem;
margin-top: 10px;
}
.form-group {
margin-bottom: 20px;
}
label {
font-size: 1.2rem;
color: white;
display: block;
margin-bottom: 5px;
}
textarea {
width: 100%;
padding: 10px;
font-size: 1rem;
border: 2px solid #fff;
border-radius: 5px;
resize: none;
background-color: #f1f1f1;
}
button {
background-color: #fff;
color: #333;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
font-weight: 600;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #f39c12;
color: white;
}
textarea[readonly] {
background-color: #e1e1e1;
color: #333;
}
@media (max-width: 768px) {
.container {
padding: 20px;
}
header h1 {
font-size: 2rem;
}
label {
font-size: 1rem;
}
}
function convertBinaryToASCII() {
let binaryInput = document.getElementById("binary-input").value.trim();
let binaryArray = binaryInput.split(' '); // Split binary input into array
let asciiResult = '';
// Iterate over each binary code and convert it to ASCII
for (let i = 0; i < binaryArray.length; i++) {
let binaryCode = binaryArray[i];
if (binaryCode.length === 8 && /^[01]+$/.test(binaryCode)) {
let decimalValue = parseInt(binaryCode, 2); // Convert binary to decimal
asciiResult += String.fromCharCode(decimalValue); // Convert decimal to ASCII
} else {
alert("Invalid binary input. Ensure all codes are 8 bits.");
return;
}
}
// Display the result in the output textarea
document.getElementById("ascii-output").value = asciiResult;
}