- '超大数的十六进制转换
- Option Explicit
- Function HEXTODEC(ByVal x As String) As String '16进制到10进制
- Dim A() As String, i As Long, UNIT As Integer
- For i = 1 To Len(x)
- If Not IsNumeric("&h" & Mid(x, i, 1)) Then MsgBox "NOT A HEX FORMAT!", 64, "INFO": Exit Function
- Next
- x = String((6 - Len(x) Mod 6) Mod 6, "0") & x
- UNIT = Len(x) / 6 - 1
- ReDim A(UNIT)
- For i = 0 To UNIT
- A(i) = CLng("&h" & Mid(x, i * 6 + 1, 6))
- Next
- For i = 0 To UNIT
- A(i) = multi(A(i), POWERS(UNIT - i))
- HEXTODEC = sums(HEXTODEC, A(i))
- Next
- End Function
- Function POWERS(ByVal x As Integer) As String ' GET 16777216^X,ie 16^(6*x)(16777216的X 次方)
- POWERS = 1
- Dim i As Integer
- For i = 1 To x
- POWERS = multi(POWERS, CLng(&H1000000))
- Next
- End Function
- Function multi(ByVal x As String, ByVal y As String) As String 'multi of two huge hexnum(两个大数之积)
- Dim Result As Variant
- Dim xl As Long, yl As Long, temp As Long, i As Long
- xl = Len(Trim(x))
- yl = Len(Trim(y))
- ReDim Result(1 To xl + yl)
- For i = 1 To xl
- For temp = 1 To yl
- Result(i + temp) = Result(i + temp) + Val(Mid(x, i, 1)) * Val(Mid(y, temp, 1))
- Next
- Next
- For i = xl + yl To 2 Step -1
- temp = Result(i) / 10
- Result(i) = Result(i) Mod 10
- Result(i - 1) = Result(i - 1) + temp
- Next
- If Result(1) = "0" Then Result(1) = ""
- multi = Join(Result, "")
- Erase Result
- End Function
- Function sums(ByVal x As String, ByVal y As String) As String ' sum of two hugehexnum(两个大数之和)
- Dim max As Long, temp As Long, i As Long, Result As Variant
- max = IIf(Len(x) >= Len(y), Len(x), Len(y))
- x = Right(String(max, "0") & x, max)
- y = Right(String(max, "0") & y, max)
- ReDim Result(0 To max)
- For i = max To 1 Step -1
- Result(i) = Val(Mid(x, i, 1)) + Val(Mid(y, i, 1))
- Next
- For i = max To 1 Step -1
- temp = Result(i) / 10
- Result(i) = Result(i) Mod 10
- Result(i - 1) = Result(i - 1) + temp
- Next
- If Result(0) = 0 Then Result(0) = ""
- sums = Join(Result, "")
- Erase Result
- End Function
- Private Sub Form_Load()
- MsgBox HEXTODEC("178BFBFF00040F32")
- End Sub
超大数的十六进制转换
最新推荐文章于 2021-07-21 23:29:02 发布