ASP常用进制转化类(2,8,10,16,32,64)
生活随笔
收集整理的這篇文章主要介紹了
ASP常用进制转化类(2,8,10,16,32,64)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<%
' 名稱:HDOBTools
' 描述:進制轉化類
' 作用:用于各種進轉的轉化
Class HDOBToolsPrivate hdobHackPrivate Sub Class_Initialize()Set hdobHack = New HDOBTools_HackEnd SubPrivate Sub Class_Terminate()Set hdobHack = NothingEnd Sub' 十進制轉二進制Function Bit(num)Bit = Dec2Other(num,2)End Function' 十進制轉八進制' 此函數其實不必添加,只是為了補全,所以需借助附加類Function [Oct](num)[Oct] = hdobHack.dec2oct(num)End Function' 十進制轉十六進制' 此函數其實不必添加,只是為了補全,所以需借助附加類Function [Hex](num)[Hex] = hdobHack.dec2hex(num)End Function' 十進制轉三十二進制' 自我擴展的:Str16_31 = "GHIJKLMNOPQRSTUV"Function Ext32(num)Ext32 = Dec2Other(num,32)End Function' 十進制轉六十四進制' 自我擴展的:Str16_31 = "GHIJKLMNOPQRSTUV"' 自我擴展的:Str32_63 = "WXYZ+=abcdefghijklmnopqrstuvwxyz"Function Ext64(num)Ext64 = Dec2Other(num,64)End Function' 二進制轉十進制Function Bit2Dec(num)Bit2Dec = Other2Dec(num,2)End Function' 八進制轉十進制Function Oct2Dec(num)Oct2Dec = Other2Dec(num,8)End Function' 十六進制轉十進制Function Hex2Dec(num)Hex2Dec = Other2Dec(num,16)End Function' 各種進制的轉化Function Other2Other(num,x1,x2)If x1=x2 Then Other2Other = num : Exit FunctionIf x1 = 10 ThenOther2Other = Dec2Other(num,x2)ElseIf x2 = 10 ThenOther2Other = Other2Dec(num,x1) ElseOther2Other = Dec2Other(Other2Dec(num,x1),x2)End IfEnd Function' 十進制轉x(x=2,8,16,32,64)進制' 結果為字符串' 注:對于2,8進制,結果為(全)數字字符串,對于16以上進制,結果不一定為數字字符串Function Dec2Other(num,x)'對于十進制轉8或16進制,有專門的內置函數可用(當然,也可按常規轉化)If x = 8 ThenDec2Other = Oct(num) : Exit FunctionElseIf x = 16 ThenDec2Other = Hex(num) : Exit FunctionEnd If'Dim Str16_31 : Str16_31 = "GHIJKLMNOPQRSTUV" '32位'Dim Str32_63 : Str32_63 = "WXYZ+=abcdefghijklmnopqrstuvwxyz" '64位Dim strBit : strBit = EmptyDim tmpDo tmp = (num Mod x)If tmp = 36 Thentmp = "+"ElseIf tmp = 37 Thentmp = "="ElseIf tmp > 37 Then 'a(97-->38)tmp = Chr(97+tmp-37-1)ElseIf tmp > 9 Then tmp = Chr(65+tmp-9-1)End IfstrBit= tmp & strBitnum=num \ xLoop While Not num <= xIf num = 36 Thennum = "+"ElseIf num = 37 Thennum = "="ElseIf num > 37 Thennum = Chr(97+num-37-1)ElseIf num > 9 Then num = Chr(65+num-9-1)End IfDec2Other=num&strBitDo While Instr(Dec2Other,"0") = 1Dec2Other = Mid(Dec2Other,2,Len(Dec2Other))LoopEnd Function' x(x=2,8,16,32,64)進制轉十進制' 結果為整型數字Function Other2Dec(num,x)Dim tmpDim cDecNumber : cDecNumber=0For inum=0 to len(num)-1tmp = mid(num,len(num)-inum,1)If Not isNumeric(tmp) ThenIf tmp = "+" Thentmp = 36ElseIF tmp = "=" Thentmp = 37ElseIf asc(tmp) > 97 Thentmp = (asc(tmp)-97+37+1)ElseIf asc(tmp) > 65 Thentmp = (asc(tmp)-65+9+1)End IfElsetmp = Int(tmp)End IfcDecNumber=cDecNumber + x ^ inum * tmpNextOther2Dec=cDecNumberEnd Function
End Class' 附加類,用于防止與同名內置函數的沖突導致的堆棧溢出
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Class HDOBTools_HackFunction Dec2Oct(num)Dec2Oct = Oct(num)End FunctionFunction Dec2Hex(num)Dec2Hex = Hex(num)End Function
End Class
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%>
?
轉載于:https://www.cnblogs.com/dreamyoung/archive/2012/09/28/2706779.html
總結
以上是生活随笔為你收集整理的ASP常用进制转化类(2,8,10,16,32,64)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 征途堆积出友情的永恒「堆优化dp」
- 下一篇: 倒水问题(Java)