tsql - Using 0x800 in SQL WHERE Clause -


i trying decipher sql statements using, sql profiler, run proprietary application.

one of statements is:

select id, groups, name, gallery dashboardreports (groups & 0x800) <> 0 , root = 1 order name 

can explain how clause works? i've never seen clause before , "groups" column contains integer values such 2048,2176,150 , 414.

thanks danny

this bitwise operation - http://en.wikipedia.org/wiki/bitwise_operation

0x800 in hexadecimal 2048 same writing (groups & 2048) <> 0

this clause telling query filter out records have 12th bit in groups column turned off.

2048 means 12th bit turned on (it makes more sense when @ number binary value).

0000 1000 0000 0000 = 2048 

it's convenient way store several on/off values in single column. 150 combination of bits (128 , 32) both these evaluate true:

(groups & 128) <> 0 (groups & 32) <> 0 

here's quick list of bits , values you:

1  1 2  2 3  4 4  8 5  16 6  32 7  64 8  128 9  256 10 512 11 1024 12 2048 

this article may - http://www.codeproject.com/kb/cpp/bitbashing.aspx


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -