[-AI-] base36 編碼解碼器(原始碼)

看板EzHotKey作者 (-.-)時間15年前 (2010/10/15 23:51), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
此函數可以讓使用者 10進位與36進位互轉 例如: 10←→A , 35←→Z , 36←→10 詳細介紹 http://en.wikipedia.org/wiki/Base_36 ===================================== #include <Array.au3> MsgBox(0,"",base36_decoder("aabbbc")) ;//必須使用字串("")傳入 MsgBox(0,"",base36_encoder("479927")) ;//使用數字或字串都行 Func base36_decoder($de) Global $ff[36] ;//為了讓函數可以獨立使用 ; 所以把編碼表寫在函數理 For $o = 0 to 35 if $o < 10 Then $ff[$o] = ChrW($o+48) Else $ff[$o] = ChrW($o+87) EndIf Next $ss = StringSplit($de,"") $up = 0 for $fs = 1 to $ss[0] $up = $up + _ArraySearch($ff,_ArrayPop( $ss))*(36^($fs-1)) ;MsgBox(0,"",$up) Next Return $up EndFunc Func base36_encoder($de) Global $ff[36] Global $ss[1] For $o = 0 to 35 if $o < 10 Then $ff[$o] = ChrW($o+48) Else $ff[$o] = ChrW($o+87) EndIf Next $ss[0] = 1 While( $de >36 ) $sde = Mod($de,36) $de = Int( $de /36) _ArrayAdd($ss, $ff[$sde]) $ss[0]= $ss[0] +1 WEnd If $de < 36 Then _ArrayAdd($ss, $ff[$de]) EndIf Dim $up For $fpp = UBound($ss) -1 to 1 Step -1 $up =$up & $ss[$fpp] Next Return $up EndFunc ================================================= ※這次就不做GUI版本了,之前的文中載點好像也不見了,都有原始碼就不補了 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.242.1.193 ※ 編輯: wait999 來自: 111.242.2.206 (12/05 19:21)
文章代碼(AID): #1Ck7YHM6 (EzHotKey)
文章代碼(AID): #1Ck7YHM6 (EzHotKey)