Arte SheetsLearn. Try. Understand.

Statistical & Engineering

Bitwise Permission Flag Extraction & Bit-Shift Formula (INT & MOD Powers of 2)

Test individual permission bits inside integer RBAC bitmasks using INT(MOD(mask / 2^bit, 2)) and perform exact left/right bit shifts (mask * 2^s and INT(mask / 2^s)) in any spreadsheet.

Decode packed RBAC permission integers and hardware status registers!

Database access-control tables, Unix file modes, and IoT status registers pack independent boolean flags into a single non-negative integer M: bit 0 (value 1 = Read), bit 1 (value 2 = Write), bit 2 (value 4 = Execute), bit 3 (value 8 = Admin). For example, M = 13 (binary 1101 = 8 + 4 + 0 + 1) grants Read, Execute, and Admin while denying Write!

Dividing M by 2^k shifts bit k into the ones place, so INT(MOD(M / (2 ^ k), 2)) extracts the exact 0/1 state of bit k (equivalent to BITAND(M, 2^k) > 0)! Similarly, left-shifting by s bits equals M * (2 ^ s) (BITLSHIFT) and unsigned right-shifting equals INT(M / (2 ^ s)) (BITRSHIFT).

Bit Position k (Weight 2^k)Permission FlagMask M = 13 (1101_2)Extracted Bit
k = 0 (Weight 1)ReadINT(MOD(13 / 1, 2))1 (Granted)
k = 1 (Weight 2)WriteINT(MOD(13 / 2, 2))0 (Denied)
k = 2 (Weight 4)ExecuteINT(MOD(13 / 4, 2))1 (Granted)
k = 3 (Weight 8)AdminINT(MOD(13 / 8, 2))1 (Granted)

Extract Single Permission Bit k (0 or 1) from Integer Mask M

Returns 1 when bit index B3 (0-based) is set inside non-negative integer bitmask B2, or 0 otherwise.

=IF(OR(B2 < 0, B3 < 0), "Invalid Mask or Bit", INT(MOD(B2 / (2 ^ B3), 2)))

Left Bit-Shift (BITLSHIFT) & Right Bit-Shift (BITRSHIFT) by s Bits

Shifts integer B2 left by B4 bit positions via multiplication by 2^B4.

=IF(OR(B2 < 0, B4 < 0), "Invalid Shift", B2 * (2 ^ B4))

Try the example

Use the original values or change them to test your understanding.

Further reading