Set specific bit in byte

前端 未结 5 537
故里飘歌
故里飘歌 2020-11-30 19:29

I\'m trying to set bits in Java byte variable. It does provide propper methods like .setBit(i). Does anybody know how I can realize this?

I can iterate

5条回答
  •  不知归路
    2020-11-30 19:52

    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); Get the bitmap : byte bitMap = myByte.toByteArray()[0];

提交回复
热议问题