给你个强点的——我编写的2到35进制字符串函数。其实主要受字符限制,否则任意进制都可以。Function GetStrByNumber(ByVal pNumber As Long, ByVal pMode As Long) As String 'GetStrByNumber函数 '语法:OutStr=GetStrByNumber(pNumber, pMode) '功能:返回数字的指定进制表示的字符串。 '参数:pNumber 一个数字,必须是正整数。 ' pMode 进制,必须在2-35之间。 '返回:OutStr 以指定进制代表的字符串。 Dim tOutStr As String Dim tBit As Integer Dim tLoop As Integer Dim tStrTable(35) As String
For tLoop = 48 To 57 tStrTable(tLoop - 48) = Chr(tLoop) Next
For tLoop = 65 To 90 tStrTable(tLoop - 55) = Chr(tLoop) Next
tBit = Fix(Log(pNumber) / Log(pMode)) For tLoop = 0 To tBit tOutStr = tStrTable(pNumber Mod pMode) & tOutStr pNumber = (pNumber - (pNumber Mod pMode)) \ pMode Next
GetStrByNumber = tOutStr End Function
'十进制到二进制 Public Function ToBinary(Num As Long) As String Do ToBinary = Num Mod 2 & ToBinary Num = Num \ 2 Loop While Num End Function'二进制到十进制 Public Function ToDecimal(BinStr As String) As Long Dim i As Long For i = 1 To Len(BinStr) ToDecimal = ToDecimal * 2 + Val(Mid(BinStr, i, 1)) Next i End Function'下面的更快一些 http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=187068以上例子满足一般需要,如需转换长度大于8的十六进制串,请看 http://expert.csdn.net/Expert/topic/2974/2974472.xml?temp=.7513391 另, 十六进制转十进制 八进制转十进制 用Val函数就可满足一般需要 Val(&HFF)'255 Val(&O10)'8,注意,&后面是字母O,不是数字0
不知道ariexcorn() 兄的十进制转二进制 bin是怎么通过的?
'GetStrByNumber函数
'语法:OutStr=GetStrByNumber(pNumber, pMode)
'功能:返回数字的指定进制表示的字符串。
'参数:pNumber 一个数字,必须是正整数。
' pMode 进制,必须在2-35之间。
'返回:OutStr 以指定进制代表的字符串。
Dim tOutStr As String
Dim tBit As Integer
Dim tLoop As Integer
Dim tStrTable(35) As String
For tLoop = 48 To 57
tStrTable(tLoop - 48) = Chr(tLoop)
Next
For tLoop = 65 To 90
tStrTable(tLoop - 55) = Chr(tLoop)
Next
tBit = Fix(Log(pNumber) / Log(pMode))
For tLoop = 0 To tBit
tOutStr = tStrTable(pNumber Mod pMode) & tOutStr
pNumber = (pNumber - (pNumber Mod pMode)) \ pMode
Next
GetStrByNumber = tOutStr
End Function
Public Function ToBinary(Num As Long) As String
Do
ToBinary = Num Mod 2 & ToBinary
Num = Num \ 2
Loop While Num
End Function'二进制到十进制
Public Function ToDecimal(BinStr As String) As Long
Dim i As Long
For i = 1 To Len(BinStr)
ToDecimal = ToDecimal * 2 + Val(Mid(BinStr, i, 1))
Next i
End Function'下面的更快一些
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=187068以上例子满足一般需要,如需转换长度大于8的十六进制串,请看
http://expert.csdn.net/Expert/topic/2974/2974472.xml?temp=.7513391
另,
十六进制转十进制
八进制转十进制
用Val函数就可满足一般需要
Val(&HFF)'255
Val(&O10)'8,注意,&后面是字母O,不是数字0