VB6位运算 - lyserver(CSDN) 转载
- '位左移
- Public Function SHL(nSource As Long, n As Byte) As Long
- SHL = nSource * 2 ^ n
- End Function
- '位右移
- Public Function SHR(nSource As Long, n As Byte) As Long
- SHR = nSource / 2 ^ n
- End Function
- '获得指定的位
- Public Function GetBits(nSource As Long, n As Byte) As Boolean
- GetBits = nSource And 2 ^ n
- End Function
- '设置指定的位
- Public Function SetBits(nSource As Long, n As Byte) As Long
- SetBits = nSource Or 2 ^ n
- End Function
- '清除指定的位
- Public Function ResetBits(nSource As Long, n As Byte) As Long
- ResetBits = nSource And Not 2 ^ n
- End Function