In Java, is it possible to clear a bit?

yes, using

bits & ~(1 << n) 

where bits is an int/long and n is the n-th bit to be cleared.

(this is a useful blog post: low level bit hacks you absolutely must know)


An alternative to dfa's answer would be to use a BitSet datastructure. It supports operations such as AND, OR and XOR.

var bitset = new BitSet(K);    // Initialize a bitset with K digits.
var nthBit = bitset.get(n);    // Get Nth bit (true/false).

bitset.clear(n);               // Clears N'th bit to false.
bitset.set(n);                 // Sets N'th bit to true.
bitset.flip(n);                // Toggles N'th bit.

In your case, you'll be looking for bitset.clear(n).

If you have to use integers, then set value using bits |= (1 << N) and as dfa mentioned, clear using: bits &= ~(1 << N).