Octal to Decimal Converter Tool Code Written HTML Javascript and css.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Octal to Decimal Converter</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
color: #333;
}
.container {
background-color: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 400px;
text-align: center;
}
h1 {
color: #4CAF50;
font-size: 2em;
}
label {
display: block;
margin-bottom: 10px;
font-size: 1.1em;
}
input[type="text"] {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1em;
outline: none;
}
input[type="text"]:focus {
border-color: #4CAF50;
}
.button {
background-color: #4CAF50;
color: #fff;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1.1em;
transition: background-color 0.3s;
}
.button:hover {
background-color: #45a049;
}
.result {
margin-top: 20px;
font-size: 1.2em;
font-weight: bold;
color: #333;
}
.error {
color: red;
font-size: 1.1em;
font-weight: bold;
}
/* Responsive Design */
@media (max-width: 480px) {
.container {
padding: 20px;
}
h1 {
font-size: 1.8em;
}
input[type="text"], .button {
font-size: 1em;
}
}
</style>
</head>
<body>
<div class="container">
<h1>Octal to Decimal Converter</h1>
<label for="octalInput">Enter Octal Number:</label>
<input type="text" id="octalInput" placeholder="Enter an octal number" />
<button class="button" onclick="convertToDecimal()">Convert</button>
<div id="errorMessage" class="error"></div>
<div id="result" class="result"></div>
</div>
<script>
function convertToDecimal() {
const octalInput = document.getElementById('octalInput').value;
const errorMessage = document.getElementById('errorMessage');
const result = document.getElementById('result');
// Clear previous results and errors
result.textContent = '';
errorMessage.textContent = '';
// Check if the input is a valid octal number
if (!/^[0-7]+$/.test(octalInput)) {
errorMessage.textContent = 'Please enter a valid octal number (digits 0-7 only).';
return;
}
// Convert octal to decimal
const decimalResult = parseInt(octalInput, 8);
result.textContent = `Decimal: ${decimalResult}`;
}
</script>
</body>
</html>