You are here: Functions > SHIFT()

SHIFT()

SHIFT() moves bits in the first character of an expression or field value left or right by a specified number of bits.

Use SHIFT() in conjunction with the BYTE(), CHR() and MASK() functions to isolate and move individual bits in a record.

Function Format

SHIFT(C,N)

The SHIFT() function takes the first character of C and shifts the bits left or right by N bits. It returns a one-character long string. If C is longer than 1, the extra characters are ignored. If N is positive, the character is shifted to the left; if negative, the character is shifted to the right. All bits shifted in from either end are zeroes. If N is greater than 7 or less than -7 the result is binary zero, CHR(0).

Examples

SHIFT(CHR(22),2) = CHR(88)

00010110 becomes 01011000

SHIFT(CHR(16),-1) = CHR(8)

00010000 becomes 00001000

SHIFT(CHR(155),5) = CHR(96)

10011011 becomes 01100000