How to set/unset a bit at specific position of a long?

Viewed 28181

How to set/unset a bit at specific position of a long in Java ?

For example,

long l = 0b001100L ; // bit representation

I want to set bit at position 2 and unset bit at position 3 thus corresponding long will be,

long l = 0b001010L ; // bit representation

Can anybody help me how to do that ?

5 Answers
Related