How to set/unset a bit at specific position of a long in Java ?
For example,
long l = 0b001100L ; // bit representation
I want to s
The least significant bit (lsb) is usually referred to as bit 0, so your 'position 2' is really 'bit 1'.
long x = 0b001100; // x now = 0b001100 x |= (1<<1); // x now = 0b001110 (bit 1 set) x &= ~(1<<2); // x now = 0b001010 (bit 2 cleared)