From 832e70ba4836f792f7051ddcf3001ea62221184a Mon Sep 17 00:00:00 2001 From: Yun Date: Thu, 11 Jan 2024 21:48:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=83=A8=E5=88=86=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 10to64.go | 4 ++-- convx_test.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/10to64.go b/10to64.go index b4a4146..d6fbb38 100644 --- a/10to64.go +++ b/10to64.go @@ -11,7 +11,7 @@ import ( const base64 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/" // DecToBase64 将10进制的数字转换为64进制的字符串 -func DecToBase64(n int) string { +func Encode10To64(n int) string { if n == 0 { return "0" } @@ -30,7 +30,7 @@ func DecToBase64(n int) string { } // Base64ToDec 将64进制的字符串转换为10进制的数字 -func Base64ToDec(s string) int { +func Decode64To10(s string) int { n := 0 // 遍历字符串的每个字符 for _, c := range s { diff --git a/convx_test.go b/convx_test.go index 1e18c99..bc7ed2a 100644 --- a/convx_test.go +++ b/convx_test.go @@ -6,6 +6,24 @@ import ( "code.yun.ink/pkg/convx" ) +func Test64(t *testing.T) { + // 测试10进制转64进制 + var v_int int = 123456789 + str := convx.Encode10To64(v_int) + if str != "7MyqL" { + t.Fail() + t.Log(str) + } + + // 测试64进制转10进制 + var v_string string = "7MyqL" + i := convx.Decode64To10(v_string) + if i != 123456789 { + t.Fail() + t.Log(i) + } +} + func TestConvToString(t *testing.T) { // 日志 // t.Log("hello world")