I try to find out which bit is set using BITAND.
In database I save the user rights as BIGINT like 1101111 or 1110001.
in the sample case I must find out the elemnts in the table if the third bit is set.
In this case. The query should find the first one.
How can I do that??
Select * from USERRIGHTS
WHERE BITAND(Rightmask , 4) = 1 ??????
I found a solution. It was silly to save the right mask in this form ‘1101111’.
I should save the data in decimal format.
In this case 1101111 = 111 (in decimal) or 1110001 = 113. I converted in my application the right mask into decimla an saved in that format.
And then it was possible to check if a bit position is set or not.
This query gives the all entries what i want :-):
Select * from USERRIGHTS
WHERE BITAND(Rightmask , 16) = 16
(The third bit position is the fifth bit position from the right. This value should be used for the bitwise operations. 2^(5-1) = 16)