So can someone enlighten me as to what is happening with this bit of SQL?
(CAST(A.FIELD AS BIGINT) & 2 = 0)
I get that the field is being recast into a bigint, but is the "& 2 =0" part doing some type of base 2 comparison? Making sure it's 2^x or something?
Thanks in advance.
edit - the field in question is of type numeric (10,0)0
edit 2: it's definitely checking to see if the #2 bit is flipped. For example, when casting the field and then doing the "& 2" part, if the number is something like 256 (2^8) the equivalent is '0'. If it's 258, the result would be '2' indication the 2 bit is on.
No idea how this works though, so any clarity would be awesome.
Posts
Edit: Didn't see your edit when I posted. Here's what's going on, slightly more specifically:
2 = 00000010
254 = 11111110
The rightmost bit has two zeros, so that's zero. The second bit in the two numbers is both 1, so that's a 1. The rest of the them have a one and a zero, leaving zero (since this is an AND operation).
That leaves 00000010, which is 2.
Thanks JHunz - I was caught up thinking '&' was the operator for concatenating strings - totally whiffed on the fact that it's a bitwise operator.
Thanks!!!