From 8b46a52f8d614a20f48eab2b4ec5353788640222 Mon Sep 17 00:00:00 2001 From: weiguang Date: Thu, 26 Sep 2024 14:27:04 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=B8=81=E8=B1=AAreadme.txt=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 readme.txt diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..68f70f6 --- /dev/null +++ b/readme.txt @@ -0,0 +1 @@ +212203252 \ No newline at end of file From aab8f7b705482e81e70f5fb5e6c3851ed4a3d1b3 Mon Sep 17 00:00:00 2001 From: weiguang Date: Thu, 26 Sep 2024 14:32:18 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=B8=81=E8=B1=AAreadme.txt=E7=AC=AC?= =?UTF-8?q?=E4=BA=8C=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 68f70f6..75f29db 100644 --- a/readme.txt +++ b/readme.txt @@ -1 +1,2 @@ -212203252 \ No newline at end of file +212203252 +222222222 \ No newline at end of file From a3f3c8a5f2a83a62cfeddb79cfedf5405c806177 Mon Sep 17 00:00:00 2001 From: weiguang Date: Thu, 26 Sep 2024 14:35:36 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=B8=81=E8=B1=AAreadme.txt=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 75f29db..b63a4be 100644 --- a/readme.txt +++ b/readme.txt @@ -1,2 +1,3 @@ 212203252 -222222222 \ No newline at end of file +222222222 +dh333333333 \ No newline at end of file From 7520a70a84c39e0dbb5bb5d5819a2969cadd378f Mon Sep 17 00:00:00 2001 From: weiguang Date: Thu, 26 Sep 2024 14:45:44 +0800 Subject: [PATCH 4/5] =?UTF-8?q?dev=E5=88=86=E6=94=AF=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index b63a4be..4d88d74 100644 --- a/readme.txt +++ b/readme.txt @@ -1,3 +1,4 @@ 212203252 222222222 -dh333333333 \ No newline at end of file +dh333333333 +dh444444444 \ No newline at end of file From aca88be3e668ef27922b159ec1deae02cbfe7926 Mon Sep 17 00:00:00 2001 From: weiguang Date: Wed, 16 Oct 2024 16:02:50 +0800 Subject: [PATCH 5/5] =?UTF-8?q?html=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 26 ++++++++++++++++++++++++++ script.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 index.html create mode 100644 script.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..de2bbf3 --- /dev/null +++ b/index.html @@ -0,0 +1,26 @@ + + + + + + 进制转换器 + + + +
+

进制转换器

+ + + + + + + + + + +

+
+ + + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..81a171d --- /dev/null +++ b/script.js @@ -0,0 +1,28 @@ +function convertBase() { + const inputNumber = document.getElementById('inputNumber').value.trim(); + const fromBase = parseInt(document.getElementById('fromBase').value); + const toBase = parseInt(document.getElementById('toBase').value); + + // 验证输入数字是否符合fromBase的规则 + if (!isValidNumber(inputNumber, fromBase)) { + alert('输入的数字无效!请检查其进制格式。'); + return; + } + + // 将输入的数字从fromBase转换为十进制 + const decimalValue = parseInt(inputNumber, fromBase); + + // 将十进制数转换为toBase + const result = decimalValue.toString(toBase).toUpperCase(); + document.getElementById('result').textContent = `转换结果: ${result}`; +} + +function isValidNumber(num, base) { + const validChars = '0123456789ABCDEF'.slice(0, base); + for (let char of num.toUpperCase()) { + if (!validChars.includes(char)) { + return false; + } + } + return true; +} \ No newline at end of file