Pages

Wednesday, 27 November 2024

Binary to Hex Converter Tool

Binary to Hex Converter

Binary to Hexadecimal Converter

Convert binary numbers to hexadecimal format with ease!

/* General Reset */ * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Arial', sans-serif; background-color: #f0f0f0; display: flex; justify-content: center; align-items: center; height: 100vh; } .container { background-color: #fff; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); padding: 30px; max-width: 400px; width: 100%; text-align: center; } .header h1 { font-size: 28px; color: #4CAF50; } .header p { font-size: 16px; color: #666; margin-bottom: 20px; } .input-section, .output-section { margin-bottom: 20px; } label { font-size: 16px; color: #333; } input { width: 100%; padding: 12px; margin-top: 8px; font-size: 16px; border: 2px solid #ddd; border-radius: 8px; outline: none; } input:focus { border-color: #4CAF50; } .convert-btn { background-color: #4CAF50; color: white; font-size: 18px; padding: 12px 20px; border: none; border-radius: 8px; cursor: pointer; margin-top: 10px; transition: background-color 0.3s ease; } .convert-btn:hover { background-color: #45a049; } .footer { margin-top: 20px; font-size: 14px; color: #777; } .footer i { color: red; } function convertBinaryToHex() { // Get the binary input value const binaryInput = document.getElementById('binaryInput').value.trim(); // Check if the input is a valid binary number if (!/^[01]+$/.test(binaryInput)) { alert("Please enter a valid binary number."); return; } // Convert binary to decimal first const decimalValue = parseInt(binaryInput, 2); // Convert decimal to hexadecimal const hexValue = decimalValue.toString(16).toUpperCase(); // Display the result document.getElementById('hexOutput').value = hexValue; }