0

I can see flags like this all over c/c++ libs and codes.

#define EDIT_MASK       0x0000003f   // usually twice of the last flag minus one                                       
#define EDIT_PO_1       0x00000001
#define EDIT_PO_2       0x00000002
#define EDIT_PO_3       0x00000004  
#define EDIT_PO_4       0x00000008  
#define EDIT_PO_5       0x00000010
#define EDIT_PO_6       0x00000020

I know the "EDIT_PO_1, ..2, ..3 .. EDIT_PO_6" flags are used for bitwise flags and stuff (Use of bitwise flags -just for ref). But I don't understand the significance of the "mask flag" i.e. EDIT_MASK.

  • 1
    Does this answer your question? [What is bit masking?](https://stackoverflow.com/questions/10493411/what-is-bit-masking) – Joe Sewell Nov 23 '22 at 17:39
  • @JoeSewell I saw the post. I go to the point. But in the above example how do you calculate the mask of a given set of flags? – Suraj Jorwekar Nov 23 '22 at 17:44
  • 1
    "twice of the last flag minus one" is typically true but not very useful to think about, what's important is that it is the bitwise OR of all of the flags – harold Nov 23 '22 at 18:52
  • 1
    @harold To be more precise, "twice of the last flag minus first flag" – ReAl Nov 24 '22 at 13:23

0 Answers0