You are here: Functions > MASK()

MASK()

MASK() extracts individual bits from the first byte of a character expression. Use MASK() to identify specific bit patterns in a byte of data.

Function Format

MASK(C1,C2)

MASK() performs a bit-wise logical AND operation on the first characters of C1 and C2, returning a one-character-long string. If either parameter is longer than one byte, subsequent characters are ignored. The usual usage is to have the byte in question as C1 and a mask value as C2.

A bit-wise AND operation compares the two bytes, one bit at a time. The result for each bit position is 1 if both the corresponding bits are 1. Otherwise, the result is 0 for that bit.

Examples

MASK("A",CHR(15)) = CHR(1)

(where A = CHR(65) = 01000001, CHR(15) = 00001111, A AND CHR(15) = 00000001)