You are here: Functions > BIT()

BIT()

BIT() returns the bit string representing a specified byte position in the current record. Use BIT() to examine the individual bits in a byte. BIT() operates in a manner similar to the function BYTE().

Function Format

BIT(N)

BIT() converts the byte at location N in the current record into an eight-character-long string of 0s and 1s that represents the byte.

Examples

To assign the bit values for bytes 8, 9 and 17 to the variables b8, b9 and b17, specify:

ASSIGN b8 = BIT(8)

ASSIGN b9 = BIT(9)

ASSIGN b17 = BIT(17)

You will find:

b8 = 00110001 if the eighth byte contains “1”
b9 = 01000001 if the ninth byte contains “A”
b17 = 01100001 if the seventeenth byte contains “a”

Assume that byte position 17 contains a set of 8 credit flags. To extract all customer records that have the third bit set to one (meaning “do not ship”), specify the condition:

SUBSTR(BIT(17),3,1)="1"

In this example, SUBSTR() is used to look at the third bit.