A mask is a string of binary code that makes a bitwise AND operation of the target field, shielding the current input bit, and is sometimes referred to as a shield code.
This technique is often used in Android to set flag to determine the tag, which can be referred to the Windowmanager.java of the framework layer.
The general flag will be written in two ways that look more intuitive (assuming that the flag is set to a length of four bytes):
One:
Private final int flag_one = 1 << 0;
Private final int flag_two = 1 << 1;
Private final int flag_three = 1 << 2;
Private final int flag_four = 1 << 3;
Private final int flag_five = 1 << 4;
Private final int flag_six = 1 << 5;
Two:
Private final int flag_one = 0x00000001
Private final int flag_two = 0x00000002
Private final int flag_three = 0x00000004
Private final int flag_four = 0x00000008
Private final int flag_five = 0x00000010
Private final int flag_six = 0x00000020
The calculation involved:
Flag &= 0xFFFF;
Flag High 16 position zero, low 16 bit reserved
Flag &= ~flag_one;
Place the mark of the Flag_one position in the flag zero
Flag |= Flag_one;
Position the Flag_one in flag 1
Use of masks in Android