积极答复者
提供一个2进制字符串(string)转换为10进制(integer)的函数

问题
-
''' <summary>
''' 表示十进制的二进制字符串
''' </summary>
''' <param name="Bin">表示二进制的字符串</param>
''' <returns>返回十进制结果</returns>
''' <remarks></remarks>
Public Function BIN_to_Dec(ByVal Bin As String) As Integer
Dim intDec As Integer '保存最终结果
Dim intBinLen As Integer '录入的2进制字符串长度
Dim intLocation As Integer '定位要处理的2进制字符的位置
Dim intPresentBit As Integer '当前2制进的10进制值intBinLen = Len(Bin)
intLocation = intBinLenFor i = 0 To intBinLen - 1
intPresentBit = CInt((Mid(Bin, intLocation, 1))) * 2 ^ i
intLocation -= 1
intDec += intPresentBit
Next iReturn intDec
End Function
- 已更改类型 周雪峰MVP, Moderator 2010年1月30日 14:05
答案
-
你好!
这样转换:
Convert.ToInt32("100100",2)
周雪峰- 已标记为答案 RickyLinModerator 2010年1月30日 15:27