Pages

Wednesday, 27 November 2024

HEX to Text Converter Tool

HEX to Text Converter

HEX to Text Converter

Made with ❤️ by [Your Name]

/* styles.css */ body { font-family: Arial, sans-serif; margin: 0; padding: 0; background: linear-gradient(135deg, #4facfe, #00f2fe); color: #fff; display: flex; justify-content: center; align-items: center; min-height: 100vh; } .container { background: #1e293b; border-radius: 8px; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2); padding: 20px; width: 90%; max-width: 600px; } header h1 { text-align: center; font-size: 2rem; margin-bottom: 20px; } .converter-box { display: flex; flex-direction: column; gap: 15px; } textarea { width: 100%; height: 100px; resize: none; border-radius: 5px; border: 2px solid #4facfe; background: #fff; color: #000; padding: 10px; font-size: 1rem; } textarea:focus { outline: none; border-color: #00f2fe; } button { background: #4facfe; color: #fff; border: none; padding: 10px 20px; font-size: 1rem; border-radius: 5px; cursor: pointer; transition: background 0.3s ease; } button:hover { background: #00f2fe; } footer { margin-top: 20px; text-align: center; font-size: 0.9rem; color: #ddd; } // script.js document.getElementById("convert-btn").addEventListener("click", function () { const hexInput = document.getElementById("hex-input").value.trim(); const outputField = document.getElementById("text-output"); if (!hexInput) { outputField.value = "Please enter a HEX string."; return; } try { const text = hexToText(hexInput); outputField.value = text; } catch (error) { outputField.value = "Invalid HEX string."; } }); // Function to convert HEX to Text function hexToText(hex) { if (hex.length % 2 !== 0) { throw new Error("Invalid HEX length."); } let text = ""; for (let i = 0; i < hex.length; i += 2) { const hexCode = hex.substr(i, 2); text += String.fromCharCode(parseInt(hexCode, 16)); } return text; }