vb.net 补码计算

   Private Function funcBM(ByVal strInput As Integer) As Integer

        If strInput > 127 Then

            Dim s() As Byte = {&H30, &H30, &H30, &H30, &H30, &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

你可能感兴趣的:(vb.net 补码计算)