Mask (computing)

In computer science, a mask or bitmask is data that is used for bitwise operations, particularly in a bit field.

Using a mask, multiple bits in a byte, nibble, word, etc.

can be set either on or off, or inverted from on to off (or vice versa) in a single bitwise operation.

For example, in the graphics API OpenGL, there is a command, glClear() which clears the screen or other buffers.

For example, an implementation of glClear() might look like: The advantage to this approach is that function argument overhead is decreased.

Since the minimum datum size is one byte, separating the options into separate arguments would be wasting seven bits per argument and would occupy more stack space.

To configure IP addresses on interfaces, masks start with 255 and have the large values on the left side: for example, IP address 203.0.113.129 with a 255.255.255.224 mask.

When the value of the mask is broken down into binary (0s and 1s), the results determine which address bits are to be considered in processing the traffic.

A 0-bit indicates that the address bit must be considered (exact match); a 1-bit in the mask is a "don't care".

The source/wildcard of 198.51.100.2/0.0.0.0 is the same as "host 198.51.100.2" In computer graphics, when a given image is intended to be placed over a background, the transparent areas can be specified through a binary mask.

[1] This way, for each intended image there are actually two bitmaps: the actual image, in which the unused areas are given a pixel value with all bits set to 0s, and an additional mask, in which the correspondent image areas are given a pixel value of all bits set to 0s and the surrounding areas a value of all bits set to 1s.

At run time, to put the image on the screen over the background, the program first masks the screen pixel's bits with the image mask at the desired coordinates using the bitwise AND operation.

A party trick to guess a number from which cards it is printed on uses the bits of the binary representation of the number. In the SVG file, click a card to toggle it.
Raster graphic sprites (left) and masks (right)