Function bindec(x As String) As Double ' 2 TO 10
Dim a
a = Split(x, ".")
y = 0
For i = 1 To Len(a(0))
y = y + Mid(a(0), i, 1) * 2 ^ (Len(a(0)) - i)
Next
For i = 1 To Len(a(1))
y = y + Mid(a(1), i, 1) / 2 ^ i
Next
bindec = y
End Function
二进制转十进制
Public Function Dec(ByVal n As String) As Double
Dim i As Long, j As Long, dot As Long, prefix As Long
prefix = Sgn(n)
If prefix = -1 Then n = Mid(n, 2)
dot = InStr(n, ".")
If dot = 0 Then
dot = Len(n) - 1
Else
n = Left(n, dot - 1) & Mid(n, dot + 1)
dot = dot - 2
End If
For i = dot To dot - Len(n) + 1 Step -1
j = j + 1
If Mid(n, j, 1) <> 0 Then Dec = Dec + 2 ^ i
Next
Dec = Dec * prefix
End Function