VB 10进制转16进制问题
知道一般的情况可用Hex来求~~但大的数(比如:888888888888)就提示溢出了~~~如果现在要写一个小程序,可转换一些比较大的10进制数字到16进制。。该怎么写呢...
知道一般的情况可用Hex来求~~
但大的数(比如:888888888888)就提示溢出了~~~
如果现在要写一个小程序,可转换一些比较大的10进制数字到16进制。。该怎么写呢 ??
以两个文本框和一个按钮为例! 展开
但大的数(比如:888888888888)就提示溢出了~~~
如果现在要写一个小程序,可转换一些比较大的10进制数字到16进制。。该怎么写呢 ??
以两个文本框和一个按钮为例! 展开
5个回答
展开全部
终于写出来了,任意长度的十进制数转换为十六进制数,完全按要求:两个文本框和一个按钮,其中Text1输入十进制数,单击按钮,在Text2中显示相应的十六进制数。
Private Sub Command1_Click()
Dim R As String, S As String
R = Text1.Text
S = Ten16(R)
Text2.Text = S
End Sub
Private Function Ten16(ByVal X As String) As String '十进制数转为十六进制数,以字符串输入输出
Dim A() As String, M As Integer, N As Integer, R As String, i As Integer, L As Integer
Do While X <> ""
L = Len(X)
ReDim A((L - 1) \ 3)
R = X: i = 0
Do While Len(R) > 3
A(i) = Left(R, 3): R = Right(R, Len(R) - 3)
i = i + 1
Loop
A(i) = R
R = ""
For i = 0 To UBound(A)
M = Val(A(i)) \ 16: N = Val(A(i)) Mod 16
If Len(Trim(Str(M))) = 2 And i < UBound(A) Then
R = R + "0" + Trim(Str(M))
Else
R = R + Trim(Str(M))
End If
If N = 0 Then R = R + "0"
If i = UBound(A) Then
Ten16 = Hex(N) + Ten16
Exit For
End If
A(i + 1) = Trim(Str(N)) + A(i + 1)
Next i
R = Replace(R, " ", "")
Do While Left(R, 1) = "0"
R = Right(R, Len(R) - 1)
Loop
X = R
Loop
Ten16 = Replace(Ten16, " ", "")
End Function
Private Sub Command1_Click()
Dim R As String, S As String
R = Text1.Text
S = Ten16(R)
Text2.Text = S
End Sub
Private Function Ten16(ByVal X As String) As String '十进制数转为十六进制数,以字符串输入输出
Dim A() As String, M As Integer, N As Integer, R As String, i As Integer, L As Integer
Do While X <> ""
L = Len(X)
ReDim A((L - 1) \ 3)
R = X: i = 0
Do While Len(R) > 3
A(i) = Left(R, 3): R = Right(R, Len(R) - 3)
i = i + 1
Loop
A(i) = R
R = ""
For i = 0 To UBound(A)
M = Val(A(i)) \ 16: N = Val(A(i)) Mod 16
If Len(Trim(Str(M))) = 2 And i < UBound(A) Then
R = R + "0" + Trim(Str(M))
Else
R = R + Trim(Str(M))
End If
If N = 0 Then R = R + "0"
If i = UBound(A) Then
Ten16 = Hex(N) + Ten16
Exit For
End If
A(i + 1) = Trim(Str(N)) + A(i + 1)
Next i
R = Replace(R, " ", "")
Do While Left(R, 1) = "0"
R = Right(R, Len(R) - 1)
Loop
X = R
Loop
Ten16 = Replace(Ten16, " ", "")
End Function
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
结果是:CEF5E80E38
这里涉及到大数精确计算的问题,需单独编程才能实现。
由于代码长,所以这里就不贴了。
这里涉及到大数精确计算的问题,需单独编程才能实现。
由于代码长,所以这里就不贴了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
试试定义Currency类型
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上的高手,你的答案有点问题啊,你试试输入16,或32看看啊。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询