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

前端 未结 5 507
粉色の甜心
粉色の甜心 2020-12-24 03:35

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

5条回答
  •  滥情空心
    2020-12-24 03:37

    Please see the class java.util.BitSet that do the job for you.

    To set : myByte.set(bit); To reset : myByte.clear(bit); To fill with a bool : myByte.set(bit, b); To get the bool : b = myByte.get(bit);

提交回复
热议问题