超大数的十六进制转换

  1. '超大数的十六进制转换
  2. Option Explicit
  3. Function HEXTODEC(ByVal x As StringAs String '16进制到10进制
  4.     Dim A() As String, i As Long, UNIT As Integer
  5.     For i = 1 To Len(x)
  6.         If Not IsNumeric("&h" & Mid(x, i, 1)) Then MsgBox "NOT A HEX FORMAT!", 64, "INFO"Exit Function
  7.     Next
  8.     x = String((6 - Len(x) Mod 6) Mod 6, "0") & x
  9.     UNIT = Len(x) / 6 - 1
  10.     ReDim A(UNIT)
  11.     For i = 0 To UNIT
  12.         A(i) = CLng("&h" & Mid(x, i * 6 + 1, 6))
  13.     Next
  14.     For i = 0 To UNIT
  15.         A(i) = multi(A(i), POWERS(UNIT - i))
  16.         HEXTODEC = sums(HEXTODEC, A(i))
  17.     Next
  18. End Function
  19. Function POWERS(ByVal x As IntegerAs String ' GET 16777216^X,ie 16^(6*x)(16777216的X 次方)
  20.     POWERS = 1
  21.     Dim i As Integer
  22.     For i = 1 To x
  23.         POWERS = multi(POWERS, CLng(&H1000000))
  24.     Next
  25. End Function
  26. Function multi(ByVal x As StringByVal y As StringAs String 'multi of two huge hexnum(两个大数之积)
  27.     Dim Result As Variant
  28.     Dim xl As Long, yl As Long, temp As Long, i As Long
  29.     xl = Len(Trim(x))
  30.     yl = Len(Trim(y))
  31.     ReDim Result(1 To xl + yl)
  32.     For i = 1 To xl
  33.         For temp = 1 To yl
  34.             Result(i + temp) = Result(i + temp) + Val(Mid(x, i, 1)) * Val(Mid(y, temp, 1))
  35.         Next
  36.     Next
  37.     For i = xl + yl To 2 Step -1
  38.         temp = Result(i) / 10
  39.         Result(i) = Result(i) Mod 10
  40.         Result(i - 1) = Result(i - 1) + temp
  41.     Next
  42.     If Result(1) = "0" Then Result(1) = ""
  43.     multi = Join(Result, "")
  44.     Erase Result
  45. End Function
  46. Function sums(ByVal x As StringByVal y As StringAs String ' sum of two hugehexnum(两个大数之和)
  47.     Dim max As Long, temp As Long, i As Long, Result As Variant
  48.     max = IIf(Len(x) >= Len(y), Len(x), Len(y))
  49.     x = Right(String(max, "0") & x, max)
  50.     y = Right(String(max, "0") & y, max)
  51.     ReDim Result(0 To max)
  52.     For i = max To 1 Step -1
  53.         Result(i) = Val(Mid(x, i, 1)) + Val(Mid(y, i, 1))
  54.     Next
  55.     For i = max To 1 Step -1
  56.         temp = Result(i) / 10
  57.         Result(i) = Result(i) Mod 10
  58.         Result(i - 1) = Result(i - 1) + temp
  59.     Next
  60.     If Result(0) = 0 Then Result(0) = ""
  61.     sums = Join(Result, "")
  62.     Erase Result
  63. End Function
  64. Private Sub Form_Load()
  65.     MsgBox HEXTODEC("178BFBFF00040F32")
  66. End Sub
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值