Pages

Wednesday, 4 December 2024

Decimal to Hex Converter Tool



Decimal to Hex Converter

Decimal to Hex Converter

Hexadecimal Output:

0x

© 2024 Decimal to Hex Converter

/* General Styles */ body { font-family: 'Roboto', sans-serif; background-color: #f7f7f7; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; color: #333; } .container { background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1); text-align: center; width: 100%; max-width: 400px; } h1 { color: #4CAF50; font-size: 2.5rem; margin-bottom: 20px; } h2 { color: #ff5733; margin-top: 20px; font-size: 1.8rem; } p { font-size: 1.5rem; color: #008cba; } .converter-box { margin-bottom: 20px; } label { font-size: 1.2rem; color: #555; } input { padding: 10px; font-size: 1rem; width: 100%; margin-top: 10px; border-radius: 4px; border: 1px solid #ccc; margin-bottom: 15px; } button { padding: 12px 20px; background-color: #4CAF50; border: none; color: white; font-size: 1rem; cursor: pointer; border-radius: 4px; transition: background-color 0.3s; } button:hover { background-color: #45a049; } footer { margin-top: 20px; font-size: 0.9rem; color: #777; } /* Responsiveness */ @media (max-width: 600px) { h1 { font-size: 2rem; } h2 { font-size: 1.5rem; } p { font-size: 1.2rem; } input { font-size: 1rem; } button { font-size: 1rem; padding: 10px 18px; } } // Get references to DOM elements const decimalInput = document.getElementById('decimalInput'); const convertBtn = document.getElementById('convertBtn'); const hexOutput = document.getElementById('hexOutput'); // Add event listener for button click convertBtn.addEventListener('click', function() { const decimalValue = parseInt(decimalInput.value); if (isNaN(decimalValue) || decimalValue < 0) { hexOutput.textContent = "Please enter a valid positive decimal number."; hexOutput.style.color = 'red'; } else { const hexValue = decimalValue.toString(16).toUpperCase(); hexOutput.textContent = `0x${hexValue}`; hexOutput.style.color = '#008cba'; } });