当前位置: 代码迷 >> C# >> C#莫非不支持long 的移动位操作
  详细解决方案

C#莫非不支持long 的移动位操作

热度:60   发布时间:2016-05-05 04:11:36.0
C#难道不支持long 的移动位操作
long workerIdBits = 5L;
long maxWorkerId = -1L ^ (-1L << workerIdBits); 

直接报错
错误 1 运算符“<<”无法应用于“long”和“long”类型的操作数

该如何解决
------解决思路----------------------
workerIdBits只能是int
------解决思路----------------------
偏移量定义为 long,你想位移多少位?
------解决思路----------------------
int  workerIdBits = 5;
long maxWorkerId = -1L ^ (-1L << workerIdBits); 

long也就64位,左移64次以上(workerIdBits  > 64)就没有实际意义了。
  相关解决方案