1,十进制转十六进制文章源自公式库网-https://www.gongshiku.com/html/202005/vbbianchengshijinzhi-shiliujinzhi-erjinzhijiandezhuanhuandaima.html
value = Trim$(value)
If Len(value) = 0 Then
Dec2Hex = ""
Else
Dec2Hex = Hex(value)
End If
If Len(Dec2Hex) = 1 Then
Dec2Hex = "0" & Dec2Hex
ElseIf Len(Dec2Hex) <> 2 Then
Dec2Hex = "ERR"
MsgBox ("変数の長さはただしくない")
End If
End Function
文章源自公式库网-https://www.gongshiku.com/html/202005/vbbianchengshijinzhi-shiliujinzhi-erjinzhijiandezhuanhuandaima.html
2,十六进制转十进制文章源自公式库网-https://www.gongshiku.com/html/202005/vbbianchengshijinzhi-shiliujinzhi-erjinzhijiandezhuanhuandaima.html
value = Trim$(value)
If Len(value) = 0 Then
MsgBox "error"
Exit Function
End If
Hex2Dec = CByte("&H" & value)
End Function
文章源自公式库网-https://www.gongshiku.com/html/202005/vbbianchengshijinzhi-shiliujinzhi-erjinzhijiandezhuanhuandaima.html
2,十进制转二进制文章源自公式库网-https://www.gongshiku.com/html/202005/vbbianchengshijinzhi-shiliujinzhi-erjinzhijiandezhuanhuandaima.html
以下VB函数可以完成十进制转换二进制的工作。另外,这个函数还加入了对二进制长度的判断,如果转换出来的二进制长度低于最小值,函数会自动在二进制字符串前补0。文章源自公式库网-https://www.gongshiku.com/html/202005/vbbianchengshijinzhi-shiliujinzhi-erjinzhijiandezhuanhuandaima.html
As String
' Returns a string containing the binary
' representation of a positive integer.
Dim result As String
Dim ExtraDigitsNeeded As Integer
' Make sure value is not negative.
DecimalValue = Abs(DecimalValue)
' Construct the binary value.
Do
result = CStr(DecimalValue Mod 2) & result
DecimalValue = DecimalValue 2
Loop While DecimalValue > 0
' Add leading zeros if needed.
ExtraDigitsNeeded = MinimumDigits - Len(result)
If ExtraDigitsNeeded > 0 Then
result = String(ExtraDigitsNeeded, "0") & result
End If
DecimalToBinary = result
End Function