前端之家收集整理的这篇文章主要介绍了
vb.net 补码计算,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Private Function funcBM(ByVal strInput As Integer) As Integer
If strInput > 127 Then
Dim s() As Byte = {&H30,&H30,&H30}
Dim s1 As String
Dim i As Integer = 0
Dim val As Integer = 0
Dim sT(6) As Byte
s1 = Convert.ToString(strInput,2)
s = System.Text.Encoding.ASCII.GetBytes(s1)
For i = 0 To 6
If s(i + 1) = &H31 Then
sT(i) = &H0
ElseIf s(i + 1) = &H30 Then
sT(i) = &H1
End If
Next
For i = 0 To 6
val = val + (sT(i) << (6 - i))
Next
funcBM = 0 - (val + 1)
Else
funcBM = strInput
End If
End Function