Numbers, units, and bits
Which flags are set in the value 13?
Tools to use
A log entry flags=13 does not explain which options are enabled. Bit flags pack options assigned to 1, 2, 4, 8 and so on into one integer. Use an eight-bit unsigned example to read, test, set and clear positions. The option names here are illustrative, not changes to a real system's permissions.
Thirteen has three set bits
13 = 8 + 4 + 1
00001101
1 → option A
100 → option C
1000 → option DRadix Converter turns decimal 13 into binary 1101, or 00001101 padded to eight bits. Weights 1, 4 and 8 are set. With zero-based numbering these are bits 0, 2 and 3. A flag whose value is 4 is not necessarily what someone means by the fourth bit; distinguish weights from positions.
Binary conversion cannot tell you what a bit means. Another application may assign completely different options to 13. Obtain the source specification's mapping, such as A=1, B=2, C=4 and D=8. Bitwise calculation checks that mapping; it does not infer meaning or safety from an unknown number.
Use AND to isolate the positions of interest
13 AND 4 = 4
13 AND 2 = 0
13 AND 6 = 4Choose width 8, unsigned, decimal input and AND. Inputs 13 and 4 produce 4, so that bit is present. Change the second input to 2 and the result is 0. AND returns an integer containing shared set bits, not a textual true or false.
For several flags, nonzero does not mean all are enabled. Mask 6 combines 2 and 4; 13 AND 6 equals 4. At least one is present, but not both. Testing all requires equality with the mask, while testing any requires a nonzero result. Decide which question you mean before interpreting the output.
OR sets bits; addition does something else
13 OR 2 = 15
15 OR 2 = 15
13 + 2 = 15
15 + 2 = 17To enable flag 2, 13 OR 2 gives 15. Applying OR 2 again keeps 15 because an already-set bit stays set. Addition happens to match the first time, but 15+2 is 17 and changes other positions through a carry. This explains why adding flags can fail when an operation repeats.
Before updating a real setting, compare original value, mask and result. Binary output should retain 1, 4 and 8 while adding 2. The screen only calculates; it does not edit server configuration files or device permissions.
XOR toggles rather than always clearing
13 XOR 4 = 9
9 XOR 4 = 13
13 AND 251 = 9
9 AND 251 = 9
251 = 11111011 (8 bits)13 XOR 4 gives 9, apparently clearing flag 4. But 9 XOR 4 returns 13: XOR flips the chosen position, so an absent bit is added. Explicitly setting an option OFF differs from toggling its current state.
In eight bits the clearing mask is 11111011, decimal 251. Both 13 AND 251 and 9 AND 251 give 9, so repeated clearing stays cleared. This mask depends on the width: do not copy the literal 251 into code using a different-sized field without checking the intended mask.
Keep width and signedness with the result
These examples use unsigned eight-bit values. NOT depends on width, and signed interpretation can make the same pattern display as negative. Share width, signedness, input base, operation and overflow policy along with the number so someone else can reproduce the calculation.
Finally, whether 15 is an allowed combination is a separate question. A representable pattern can contain mutually exclusive settings or reserved bits. Successful calculation is not proof that the application accepts it. Return to the system specification for valid combinations and application procedures.