# Visual FoxPro functions for bit manipulation

Visual FoxPro can manipulate numbers up to the size of a 32-bit integer as patterns of bits. Here is a list of some of the more useful boolean commands and functions. Many of them accept extra optional parameters. Look in the FoxPro Help system for more information about the syntax and use of these functions.

## Boolean operators

The simplest boolean operator is NOT. This takes a single number as a parameter. Every bit in the output number is the opposite of its equivalent in the input parameter. Every zero will be replaced by a one; every one will be replaced by a zero. FoxPro performs this operation with the BITNOT() function:

 BITNOT() returns with every bit inverted.

Three other boolean operators take two input parameters and return a single number:

• AND will produce a 1 only if both input bits are 1.
• OR will produce a 1 if either or both input bits are 1.
• XOR will produce a 1 if either but not both input bits are 1.

FoxPro implements these operators with these three functions:

 BITAND(,) return AND . BITOR(,) return OR . BITXOR(,) return XOR .

Note that each of these three functions can take more than two parameters.

## Other bitwise operators

The following FoxPro commands change or test an individual bit of a single number:

 BITCLEAR(,) return with bit set to 0. BITSET(,) return with bit set to 1. BITTEST(,) return .T. if bit of is 1.

The following commands shift the bits of a number left or right:

 BITLSHIFT(,) return with all bits shifted places to the left. The leftmost bits are set to 0. BITRSHIFT(,) return with all bits shifted places to the right. The rightmost bits are set to 0.  