What is a bitmask and a mask?

前端 未结 3 995
时光取名叫无心
时光取名叫无心 2020-12-02 07:44

On the PHP documentation about JSON it mentions the word bitmask. Wikipedia has it defined as a mask. I don\'t understand either bitmask or mask or how they are useful. Can

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 08:40

    In essence, Bitmask is a list of boolean flags (for example isAlive, isMoving, etc) compressed into a single field, usually an integer. It can cut quite a significant amount of JSON string size or memory footprint.

    This can be significant especially in PHP where a single boolean in an array can take the same amount of RAM as an integer. There is a very simple Bitmask guide that will explain step by step everything you need to know including how and when to use it.

提交回复
热议问题