ASCII to Text Converter
ASCII to Text Converter
/* General Styling */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, sans-serif;
background-color: #f0f4f8;
color: #333;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
padding: 20px;
width: 90%;
max-width: 700px;
}
.title {
text-align: center;
font-size: 2rem;
margin-bottom: 20px;
color: #4CAF50;
}
.converter-box {
display: flex;
flex-direction: column;
gap: 10px;
}
textarea {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
resize: vertical;
}
textarea:focus {
border-color: #4CAF50;
outline: none;
}
.convert-btn {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
font-size: 1.2rem;
cursor: pointer;
transition: background-color 0.3s;
border-radius: 4px;
}
.convert-btn:hover {
background-color: #45a049;
}
.footer {
text-align: center;
margin-top: 20px;
font-size: 0.9rem;
color: #888;
}
.footer a {
color: #4CAF50;
text-decoration: none;
}
.footer a:hover {
text-decoration: underline;
}
/* Responsive Design */
@media (max-width: 600px) {
.container {
padding: 15px;
width: 100%;
}
.title {
font-size: 1.5rem;
}
.convert-btn {
font-size: 1rem;
}
}
document.getElementById('convertButton').addEventListener('click', function() {
const asciiInput = document.getElementById('asciiInput').value;
const outputArea = document.getElementById('textOutput');
if (asciiInput.trim() === '') {
outputArea.value = 'Please enter ASCII characters.';
return;
}
try {
const decodedText = asciiToText(asciiInput);
outputArea.value = decodedText;
} catch (error) {
outputArea.value = 'Error: Invalid ASCII input.';
}
});
function asciiToText(asciiStr) {
const asciiArray = asciiStr.split(' ');
const text = asciiArray.map(code => {
if (!isNaN(code)) {
return String.fromCharCode(parseInt(code, 10));
}
return '';
}).join('');
return text;
}