求助函数,转换成16进制
HEX不可用的,因为要转换的数据超过Long类型范围。如:4294967295 问题点数:20、回复次数:3Top
1 楼bakw(好好潜水,天天UP)回复于 2003-12-02 19:25:16 得分 0
那就慢慢来了
mod 16
/16
一个一个来Top
2 楼cngxylyh(olo)回复于 2003-12-02 21:18:12 得分 0
用字节来转换。
dim a as byteTop
3 楼northwolves(狼行天下)回复于 2003-12-02 22:22:24 得分 20
Private Sub Command1_Click()
MsgBox dectohex("4294967295")
End Sub
Function dectohex(ByVal hugenum As String) As String ' trans hugenum to hex
Do While Not Val(hugenum) < 16
dectohex = Hex(Val(Right(hugenum, 4)) Mod 16) & dectohex
hugenum = fourth(hugenum)
hugenum = fourth(hugenum) 'devide hugenum by 4 two times
Loop
dectohex = Hex(Val(hugenum)) & dectohex
End Function
Function fourth(ByVal x As String) As String 'get fourth of x
Dim temp As String, result() As String
temp = x
Dim i As Long
ReDim result(1 To Len(temp)) As String
result(1) = Mid(temp, 1, 1) \ 4
Mid(temp, 1, 1) = Val(Mid(temp, 1, 1) Mod 4)
For i = 2 To Len(x)
result(i) = (Val(Mid(temp, i, 1)) + Val(Mid(temp, i - 1, 1)) * 10) \ 4
Mid(temp, i, 1) = (Val(Mid(temp, i, 1)) + Val(Mid(temp, i - 1, 1)) * 10) Mod 4
Next
fourth = Join(result, "")
If Left(fourth, 1) = "0" Then fourth = Right(fourth, Len(fourth) - 1) ' no zero ahead
Erase result
End FunctionTop




