求助函数,转换成16进制

kzlong 2003-12-02 06:50:22
HEX不可用的,因为要转换的数据超过Long类型范围。如:4294967295
...全文
66 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
northwolves 2003-12-02
  • 打赏
  • 举报
回复
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 Function
cngxylyh 2003-12-02
  • 打赏
  • 举报
回复
用字节来转换。
dim a as byte
笨狗先飞 2003-12-02
  • 打赏
  • 举报
回复
那就慢慢来了
mod 16
/16
一个一个来

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧