Octal to Text Converter
Octal to Text Converter
Convert your Octal code into plain text easily!
/* General Styling */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(to right, #4facfe, #00f2fe);
color: #333;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
/* Container Styling */
.container {
background: #fff;
border-radius: 10px;
padding: 20px;
max-width: 500px;
width: 100%;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
text-align: center;
}
h1 {
color: #4facfe;
margin-bottom: 10px;
}
p {
margin-bottom: 15px;
}
/* Input and Output Styling */
textarea {
width: 100%;
height: 80px;
border: 1px solid #ddd;
border-radius: 5px;
padding: 10px;
font-size: 16px;
margin-bottom: 15px;
resize: none;
}
textarea:focus {
outline: none;
border-color: #4facfe;
box-shadow: 0 0 5px rgba(79, 172, 254, 0.5);
}
button {
width: 100%;
background: #4facfe;
color: white;
border: none;
border-radius: 5px;
padding: 10px;
font-size: 16px;
cursor: pointer;
transition: background 0.3s ease;
}
button:hover {
background: #328dfd;
}
/* Error Message */
.error {
color: red;
font-size: 14px;
margin-top: 10px;
}
/* Responsive Design */
@media (max-width: 500px) {
textarea {
font-size: 14px;
}
button {
font-size: 14px;
}
}
document.getElementById("convert-btn").addEventListener("click", function () {
const octalInput = document.getElementById("octal-input").value.trim();
const errorMsg = document.getElementById("error-msg");
const textOutput = document.getElementById("text-output");
errorMsg.textContent = ""; // Clear error message
textOutput.value = ""; // Clear previous output
if (!octalInput) {
errorMsg.textContent = "Please enter octal code.";
return;
}
// Validate octal input
const octalPattern = /^[0-7\s]+$/; // Octal digits (0-7) with spaces
if (!octalPattern.test(octalInput)) {
errorMsg.textContent = "Invalid octal code. Use digits 0-7 separated by spaces.";
return;
}
try {
// Convert Octal to Text
const octalArray = octalInput.split(/\s+/); // Split by spaces
const text = octalArray
.map(octal => String.fromCharCode(parseInt(octal, 8)))
.join("");
textOutput.value = text;
} catch (error) {
errorMsg.textContent = "Conversion error. Check your input.";
}
});