''' <summary>
''' ■機能:10進数を2進数に変換する。
''' </summary>
''' <param name="Value"></param>
''' <returns>マイナスの値も考慮に入れる。16桁のうちの先頭桁数が符号</returns>
''' <remarks></remarks>
Public Shared Function Convert10to2Ex(ByVal Value As String) As String
Dim lngBit As Long
Dim strData As String
'符号桁数を確認
If (CType(Value, Integer) >= 0) Then
Value = Convert.ToInt32(CType(Value, Integer))
Else
Value = Convert.ToInt32(CType(Value, Integer) + (&HFFFF + 1))
End If
Do Until (Value < 2 ^ lngBit)
If (Value And 2 ^ lngBit) <> 0 Then
strData = "1" & strData
Else
strData = "0" & strData
End If
lngBit = lngBit + 1
Loop
'16ビット表示に変換
strData = String.Format("{0:0000000000000000}", CType(strData, Long))
Return strData
End Function
''' <summary>
''' ■機能:2進数を10進数に変換する。
''' </summary>
''' <param name="Value"></param>
''' <returns>マイナスの値も考慮に入れる。16桁のうちの先頭桁数が符号</returns>
''' <remarks></remarks>
Public Shared Function Convert2to10Ex(ByVal Value As String) As Long
Dim Ret As Long
Dim K As Long
Dim X As Long
For K = 1 To Len(Value)
If Mid(Value, Len(Value) - K + 1, 1) = "1" Then
X = 2 ^ (K - 1)
Ret = Ret + X
End If
Next K
If Ret > Short.MaxValue Then
Ret = Convert.ToInt16(Ret - (&HFFFF + 1))
Else
Ret = Convert.ToInt16(Ret)
End If
Convert2to10Ex = Ret
End Function
1070

被折叠的 条评论
为什么被折叠?



