bit mask

bit mask

(programming)A pattern of binary values which is combinedwith some value using bitwise AND with the result that bitsin the value in positions where the mask is zero are also setto zero. For example, if, in C, we want to test if bits 0or 2 of x are set, we can write

int mask = 5; /* binary 101 */

if (x & mask) ...

A bit mask might also be used to set certain bits usingbitwise OR, or to invert them using bitwise exclusive OR.