参考链接:http://dataeducation.com/bitmask-handling-part-4-left-shift-and-right-shift/
SQL Server 官网的连接:https://docs.microsoft.com/zh-cn/sql/t-sql/language-elements/bitwise-operators-transact-sql?view=sql-server-2017
C#MSDN文档说明: https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/operators/index
C#代码的
移位运算符
这些运算符的优先级比下一章节高,比上一章节低。
x << y:左移位,右侧用 0 填充。
x >> y:右移位。 如果左操作数是 int
或 long
,则左位数补符号位。 如果左操作数是 uint
或 ulong
,则左位数补零。
SQL Server 的 移位运算符处理
a << b = a * power(2, b)
a >> b = a / power(2, b)
SELECT
CAST(0xFF * POWER(CAST(256 AS BIGINT), 0) AS BINARY(12)) AS Shift0,
CAST(0xFF * POWER(CAST(256 AS BIGINT), 1) AS BINARY(12)) AS Shift1,
CAST(0xFF * POWER(CAST(256 AS BIGINT), 2) AS BINARY(12)) AS Shift2,
CAST(0xFF * POWER(CAST(256 AS BIGINT), 3) AS BINARY(12)) AS Shift3,
CAST(0xFF * POWER(CAST(256 AS BIGINT), 4) AS BINARY(12)) AS Shift4,
CAST(0xFF * POWER(CAST(256 AS BIGINT), 5) AS BINARY(12)) AS Shift5