7,759
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
'完整的
Private Sub Command1_Click()
Debug.Print dec2hex("12379814471884843981")
Debug.Print hex2dec("ABCDEFABCDEFABCD")
Debug.Print hex2dec(myand(dec2hex("4294967297"), dec2hex("4294967296")))
End Sub
Private Function myand(ByVal hexa As String, ByVal hexb As String) As String
Dim m As Long
Dim n As Long
Dim a As Byte
Dim b As Byte
Dim c As Byte
Dim r As String
m = Len(hexa)
n = Len(hexb)
If m < n Then
hexa = String(n - m, "0") & hexa
m = n
End If
If n < m Then
hexb = String(m - n, "0") & hexb
n = m
End If
Dim l As Long
l = Len(hexa)
Dim i As Long
For i = 1 To l
a = Val("&h" & Mid(hexa, i, 1))
b = Val("&h" & Mid(hexb, i, 1))
c = a And b
r = r & Trim(Hex$(c))
Next i
myand = r
End Function
Private Function dec2hex(ByVal dec As String) As String
Dim n(1 To 100) As Byte
Dim c As Byte
Dim l As Long
Dim i As Long
Dim j As Long
l = Len(dec)
For i = 1 To l
c = Val(Mid(dec, i, 1))
For j = 100 To 2 Step -1
n(j) = n(j) * 10
Next j
n(100) = n(100) + c
For j = 100 To 2 Step -1
If n(j) > 15 Then
n(j - 1) = n(j - 1) + n(j) \ 16
n(j) = n(j) Mod 16
End If
Next j
Next i
Dim s As String
For i = 1 To 100
If n(i) > 0 Then
For j = i To 100
s = s & Trim(Hex$(n(j)))
Next j
dec2hex = s
Exit Function
End If
Next i
End Function
Private Function hex2dec(ByVal hexx As String) As String
Dim n(1 To 100) As Byte
Dim c As Byte
Dim l As Long
Dim i As Long
Dim j As Long
l = Len(hexx)
For i = 1 To l
c = Val("&h" & Mid(hexx, i, 1))
For j = 100 To 2 Step -1
n(j) = n(j) * 16
Next j
n(100) = n(100) + c
For j = 100 To 2 Step -1
If n(j) > 9 Then
n(j - 1) = n(j - 1) + n(j) \ 10
n(j) = n(j) Mod 10
End If
Next j
Next i
Dim s As String
For i = 1 To 100
If n(i) > 0 Then
For j = i To 100
s = s & Trim(CStr(n(j)))
Next j
hex2dec = s
Exit Function
End If
Next i
End Function
Private Function dec2hex(ByVal dec As String) As String
Dim n(1 To 100) As Byte
Dim c As Byte
Dim l As Long
Dim i As Long
Dim j As Long
l = Len(dec)
For i = 1 To l
c = Val(Mid(dec, i, 1))
For j = 100 To 2 Step -1
n(j) = n(j) * 10
Next j
n(100) = n(100) + c
For j = 100 To 2 Step -1
If n(j) > 15 Then
n(j - 1) = n(j - 1) + n(j) \ 16
n(j) = n(j) Mod 16
End If
Next j
Next i
Dim s As String
For i = 1 To 100
If n(i) > 0 Then
For j = i To 100
s = s & Trim(Hex$(n(j)))
Next j
dec2hex = s
Exit Function
End If
Next i
End Function
Option Explicit
Private Sub Command1_Click()
Debug.Print myand("ffffffffffffffffffff", "88776")
End Sub
Private Function myand(ByVal hexa As String, ByVal hexb As String) As String
Dim m As Long
Dim n As Long
Dim a As Byte
Dim b As Byte
Dim c As Byte
Dim r As String
m = Len(hexa)
n = Len(hexb)
If m < n Then
hexa = String(n - m, "0") & hexa
m = n
End If
If n < m Then
hexb = String(m - n, "0") & hexb
n = m
End If
Dim l As Long
l = Len(hexa)
Dim i As Long
For i = 1 To l
a = Val("&h" & Mid(hexa, i, 1))
b = Val("&h" & Mid(hexb, i, 1))
c = a And b
r = r & Trim(Hex$(c))
Next i
myand = r
End Function