Updated with newer answer and better test
Let\'s say I have the number 382 which is 101111110.
How could I randomly turn a bit which is not 0 to
int val=382 int mask = ~(1 << N) // this would turn-off nth bit (0 to 31) NewVal = (int) ((uint)val & (uint)mask}