Search code examples
sqlsql-serverbitwise-operatorsbitwise-and

bitwise operation in sql


please can someone help me to understand this condition val1 & 11 = 0

SELECT val FROM table WHERE val1 & 11 = 0

available for more information. Thanks a lot


Solution

  • 11 is 1011 in base 2. The code selects rows where 1st, 2nd and 4th bits are 0. I.e. it will match where val1 in 0, 4, 16, 20, 32, 36, 48, ...