Change bits value in Byte

后端 未结 5 1760
北海茫月
北海茫月 2021-02-14 15:31

I have some data in field type Byte ( I save eight inputs in Byte, every bit is one input ). How to change just one input in that field ( Byte) but not to lose information about

5条回答
  •  醉话见心
    2021-02-14 16:22

    You really owe it to yourself to look into masking functions for and, or, and xor -- they allow you to simultaneously verify, validate, or change... one, some, or all of the bits in a byte structure in a single statement.

    I'm not a java programmer by trade, but it's derived from C and a quick search online seemed to reveal support for those bitwise operations.

    See this Wikipedia article for more information about this technique.

提交回复
热议问题