How to reset one bit in oolong?

I have a number ulong

. I need to be able to quickly set and reset a single bit. For example:

15 1111 . By setting the 5th bit, I get 47 , so 101111

I figured out how to set the bit:

ulong a = 15;
a |= 1 << 5; // so, now a=47

      

But I'm afraid how to reset back to 0. I tried:

a &= ~(1 << 5);

      

It doesn't work because I cannot use the operator &

on the variable ulong

.

What's the workaround? I need this operation to be as fast as possible.

+3


source to share


1 answer


I cannot use the operator in the variable either ulong

.

This is because it is 1

signed. Giving it an unsigned value using a U

suffix fixes the problem:



a &= ~(1U << 5);

      

Demo version

+4


source







All Articles