|
|
|
@ -0,0 +1,100 @@
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="zh">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
<title>进制转换</title>
|
|
|
|
|
<style>
|
|
|
|
|
body {
|
|
|
|
|
font-family: Arial, sans-serif;
|
|
|
|
|
margin: 20px;
|
|
|
|
|
padding: 20px;
|
|
|
|
|
background-color: #f4f4f4;
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
}
|
|
|
|
|
input, select {
|
|
|
|
|
margin-bottom: 10px;
|
|
|
|
|
padding: 8px;
|
|
|
|
|
width: 200px;
|
|
|
|
|
}
|
|
|
|
|
button {
|
|
|
|
|
padding: 10px;
|
|
|
|
|
}
|
|
|
|
|
.result {
|
|
|
|
|
margin-top: 20px;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
|
|
<h1>进制转换工具</h1>
|
|
|
|
|
<div>
|
|
|
|
|
<label for="inputNumber">输入数字 (X):</label>
|
|
|
|
|
<input type="text" id="inputNumber" placeholder="例如:1A3" />
|
|
|
|
|
|
|
|
|
|
<label for="fromBase">选择原进制:</label>
|
|
|
|
|
<select id="fromBase">
|
|
|
|
|
<option value="2">2</option>
|
|
|
|
|
<option value="3">3</option>
|
|
|
|
|
<option value="4">4</option>
|
|
|
|
|
<option value="5">5</option>
|
|
|
|
|
<option value="6">6</option>
|
|
|
|
|
<option value="7">7</option>
|
|
|
|
|
<option value="8">8</option>
|
|
|
|
|
<option value="9">9</option>
|
|
|
|
|
<option value="10">10</option>
|
|
|
|
|
<option value="11">11</option>
|
|
|
|
|
<option value="12">12</option>
|
|
|
|
|
<option value="13">13</option>
|
|
|
|
|
<option value="14">14</option>
|
|
|
|
|
<option value="15">15</option>
|
|
|
|
|
<option value="16">16</option>
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<label for="toBase">选择目标进制:</label>
|
|
|
|
|
<select id="toBase">
|
|
|
|
|
<option value="2">2</option>
|
|
|
|
|
<option value="3">3</option>
|
|
|
|
|
<option value="4">4</option>
|
|
|
|
|
<option value="5">5</option>
|
|
|
|
|
<option value="6">6</option>
|
|
|
|
|
<option value="7">7</option>
|
|
|
|
|
<option value="8">8</option>
|
|
|
|
|
<option value="9">9</option>
|
|
|
|
|
<option value="10">10</option>
|
|
|
|
|
<option value="11">11</option>
|
|
|
|
|
<option value="12">12</option>
|
|
|
|
|
<option value="13">13</option>
|
|
|
|
|
<option value="14">14</option>
|
|
|
|
|
<option value="15">15</option>
|
|
|
|
|
<option value="16">16</option>
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<button onclick="convert()">转换</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="result" id="result"></div>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
function convert() {
|
|
|
|
|
const inputNumber = document.getElementById("inputNumber").value;
|
|
|
|
|
const fromBase = parseInt(document.getElementById("fromBase").value);
|
|
|
|
|
const toBase = parseInt(document.getElementById("toBase").value);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 将输入的原进制数转换为10进制
|
|
|
|
|
const decimalValue = parseInt(inputNumber, fromBase);
|
|
|
|
|
// 将10进制数转换为目标进制
|
|
|
|
|
const convertedValue = decimalValue.toString(toBase).toUpperCase();
|
|
|
|
|
|
|
|
|
|
// 显示结果
|
|
|
|
|
document.getElementById("result").innerText = `转换结果 (Y): ${convertedValue}`;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
document.getElementById("result").innerText = "转换失败,请确保输入正确。";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|