Pages

Saturday, 21 December 2024

Byte Converter Tool



Byte Converter Tool

Byte Converter Tool

Convert between different data sizes

to
* { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: Arial, sans-serif; background-color: #f4f6f9; display: flex; justify-content: center; align-items: center; height: 100vh; } .container { background-color: #fff; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); padding: 30px; width: 400px; text-align: center; } .header h1 { color: #3f51b5; font-size: 2em; } .header p { color: #757575; } .converter { margin-top: 30px; } .input-container, .output-container { margin-bottom: 20px; } input[type="number"], input[type="text"], select { width: 100%; padding: 10px; font-size: 1em; margin: 5px 0; border-radius: 5px; border: 1px solid #ddd; outline: none; } input[type="number"], input[type="text"] { text-align: center; } select { background-color: #fafafa; } button.convert-btn { background-color: #4caf50; color: white; font-size: 1.2em; padding: 15px 30px; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s; } button.convert-btn:hover { background-color: #45a049; } footer { margin-top: 20px; font-size: 0.9em; color: #757575; } .to-unit span { font-size: 1.2em; font-weight: bold; color: #3f51b5; } function convert() { const inputValue = parseFloat(document.getElementById("inputValue").value); const inputUnit = document.getElementById("inputUnit").value; const outputUnit = document.getElementById("outputUnit").value; if (isNaN(inputValue)) { alert("Please enter a valid number."); return; } const unitConversions = { bytes: 1, kilobytes: 1024, megabytes: 1024 ** 2, gigabytes: 1024 ** 3, terabytes: 1024 ** 4 }; const inputInBytes = inputValue * unitConversions[inputUnit]; const outputValue = inputInBytes / unitConversions[outputUnit]; document.getElementById("outputValue").value = outputValue.toFixed(2); }