c# - Shifting bits of 64Bit Ints getting error -
i'm experimenting bit shifting using uint64 data type. code works expected when use constant number. however, fails when use variable. compiler issues "operator << cannot applied operands of type 'int' , 'ulong'" error. how go fixing code can use variable in place of constant number? here's excerpt of code
using system.io; using system; class program { static void main() { uint64 x=0; int pos = 2; x = ((uint64)x | (1 << pos)); console.writeline(x); } }
try making right-hand side operand of |
-operator of type uint64
, e.g.:
x = x | (1ul << pos);
btw, 1 may prefer compound form:
x |= 1ul << pos;
Comments
Post a Comment