主题:[原创]二进制转十进制
函数原形如下;
'参数;value 是一组二进制值.
'功能;二进制转换为十进制
Public Function Ex2转10(ByVal value As String) As Integer
Dim eulaV As String '存储返转后值.
Dim forValue As Integer '存储循环中取出的单个值.
Dim NextValue As Integer '存储循环完成后的总值
Dim i As Integer '用于循环
eulaV = StrReverse(value) 'StrReverse':反转字符串
MsgBox "返转前为;" & value & " 返转后为:" & eulaV
For i = 1 To Len(value)
forValue = val(Mid(eulaV, i + 1, 1))
' MsgBox forValue & "乘" & 2 & "的" & i & "次方=" & forValue * 2 ^ i
NextValue = NextValue + forValue * 2 ^ i
Next
' MsgBox NextValue
Ex2转10 = NextValue
End Function
结果错误为;当我输入
十进制 = 二进制 = 十进制
1 = 1 = 0
13 = 1101 = 12
15 = 1111 = 14
17 = 10001 = 16
19 = 10011 = 18
1235 = 10011010011 = 1234
请问这是为何呀!各位大虾指教