开发者

bigint type with & usage

开发者 https://www.devze.com 2023-03-20 13:30 出处:网络
I am seeing this first time using \'&\' symbol in sql stored procedures. declare@b bigint set @b=15

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

精彩评论

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