Why use flags+bitmasks rather than a series of booleans?

后端 未结 10 2089
猫巷女王i
猫巷女王i 2021-02-05 03:29

Given a case where I have an object that may be in one or more true/false states, I\'ve always been a little fuzzy on why programmers frequently use flags+bitmasks instead of ju

10条回答
  •  伪装坚强ぢ
    2021-02-05 04:05

    Among other things, its easier to add new bit meanings to a bitfield than to add new boolean values to a class. Its also easier to copy a bitfield from one instance to another than a series of booleans.

提交回复
热议问题