Pages

Wednesday, 4 December 2024

HEX to Text Converter Tool



HEX to Text Converter

HEX to Text Converter

Converted Text:

Your converted text will appear here...

* { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Roboto', sans-serif; background: #f4f4f9; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .container { width: 100%; max-width: 600px; padding: 30px; background-color: #fff; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); border-radius: 8px; } .header h1 { text-align: center; color: #5c6bc0; font-size: 2rem; margin-bottom: 20px; } .form-container { margin-bottom: 20px; } .form-container label { font-size: 1rem; color: #555; display: block; margin-bottom: 10px; } textarea { width: 100%; height: 120px; padding: 10px; font-size: 1rem; border: 1px solid #ccc; border-radius: 4px; resize: none; margin-bottom: 10px; } button { background-color: #5c6bc0; color: #fff; padding: 12px; font-size: 1rem; border: none; border-radius: 4px; cursor: pointer; transition: background-color 0.3s; width: 100%; } button:hover { background-color: #3f51b5; } .output h2 { color: #333; margin-bottom: 10px; font-size: 1.5rem; } .output p { background-color: #e8eaf6; padding: 10px; font-size: 1.1rem; color: #333; border-radius: 4px; min-height: 50px; word-wrap: break-word; } document.getElementById("convertBtn").addEventListener("click", function() { const hexInput = document.getElementById("hexInput").value.trim(); const outputText = document.getElementById("outputText"); if (hexInput === "") { outputText.textContent = "Please enter a HEX code."; return; } // Validate if the input is a valid hex code if (!/^([0-9A-Fa-f]{2})+$/.test(hexInput)) { outputText.textContent = "Invalid HEX code! Please enter a valid HEX code."; return; } try { // Split the input into pairs of hex characters and convert them to text let textOutput = ""; for (let i = 0; i < hexInput.length; i += 2) { const hexPair = hexInput.slice(i, i + 2); textOutput += String.fromCharCode(parseInt(hexPair, 16)); } outputText.textContent = textOutput; } catch (e) { outputText.textContent = "Error during conversion."; } });