星期四, 9月 04, 2008

VB.NET簡單存取Byte變數中各Bit

Sub WriteBit(ByRef Data As byte,ByVal BitIndex As Integer, ByVal NewBit As Boolean)

If NewBit = True Then
Data = Data And Math.Pow(2, BitIndex)
Else
Data = Data And (&HFF - Math.Pow(2, BitIndex))
End If

End Sub


Function ReadBit(ByRef Data As byte,ByVal BitIndex As Integer) as Boolean

return (Data And Math.Pow(2, BitIndex))) / Math.Pow(2, BitIndex)

End Sub

沒有留言: