开发者

bigint type with & usage

I am seeing this first time using '&' symbol in sql stored procedures.

declare  @b bigint
set @b=15
select @b&2

result is 2

Can some one ex开发者_运维技巧plain me how the result was 2??

FYI: its on SQL server 2005


& is the Bitwise And operator.

The result is 2 because;

select 15     --15 as binary: 1111
       & 2    --2 as binary:  0010
                              ----
  --AND'ing the bits yields;  0010  <- decimal 2


The & symbol is performs a bitwise logical AND operation between two integer values.

Are you trying to add 2, in which case you may be looking to use:

declare @b bigint set @b=15 select @b + 2
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜