一个字节定义如下:
停止位 校验位   b7   b6   b5   b4   b3   b2   b1 起始位
请问这个字节的最大值是多少?
另外请问由于b1到b7的值都要进行判断,如何从该字节中取出每一位进行操作?

解决方案 »

  1.   

    (a and 2^i)<>0 则i+1位为1
      

  2.   

    Private Function GetByteData(ByVal btSrc As Byte, ByVal intPos As Byte)
        Select Case intPos
                Case 0
                    GetByteData = btSrc And &H1
                Case 1
                    If (btSrc And &H2) = &H2 Then
                        GetByteData = 1
                    Else
                        GetByteData = 0
                    End If
                Case 2
                    If (btSrc And &H4) = &H4 Then
                        GetByteData = 1
                    Else
                        GetByteData = 0
                    End If
                Case 3
                    If (btSrc And &H8) = &H8 Then
                        GetByteData = 1
                    Else
                        GetByteData = 0
                    End If
                Case 4
                    If (btSrc And &H10) = &H10 Then
                        GetByteData = 1
                    Else
                        GetByteData = 0
                    End If
                Case 5
                    If (btSrc And &H20) = &H20 Then
                        GetByteData = 1
                    Else
                        GetByteData = 0
                    End If
                Case 6
                    If (btSrc And &H40) = &H40 Then
                        GetByteData = 1
                    Else
                        GetByteData = 0
                    End If
                Case 7
                    If (btSrc And &H80) = &H80 Then
                        GetByteData = 1
                    Else
                        GetByteData = 0
                    End If
        End Select
    End Function