How to Check and Combine Permission Flags with BITAND and BITOR in Excel

Read and grant user permissions stored as bit flags, the way apps and databases store them.

You will learn to

  • Test whether a flag is set with BITAND
  • Add a flag with BITOR
  • Test for several flags at once

How it works

Many systems store several yes/no settings in one number, with each setting worth a power of two: Read = 1, Write = 2, Delete = 4, Admin = 8. A user with value 5 has Read and Delete (1 + 4). BITAND(value, flag) returns the flag if it is set and 0 if not, so =BITAND(5,4)>0 is TRUE.

BITOR(value, flag) switches a flag on without disturbing the others, and is safe to repeat: BITOR(5,2) and BITOR(7,2) both include Write. To check several flags at once, combine them with BITOR and test whether BITAND returns the whole combination.

=BITAND(B2,E4)>0