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 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(<n1>) returns <n1> 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(<n1>,<n2>) return <n1> AND <n2>.
BITOR(<n1>,<n2>) return <n1> OR <n2>.
BITXOR(<n1>,<n2>) return <n1> XOR <n2>.

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(<n1>,<n2>) return <n1> with bit <n2> set to 0.
BITSET(<n1>,<n2>) return <n1> with bit <n2> set to 1.
BITTEST(<n1>,<n2>) return .T. if bit <n2> of <n1> is 1.

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

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

Related Items

Alvechurch Data - Microsoft FoxPro and Access Database Development and Training

Alvechurch Data are based close to Birmingham and provide Microsoft Access and Visual FoxPro training, development and support.

Read More

Autocomplete in Visual Fox Pro

Autocomplete in Visual Fox Pro

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.

Read More

FoxPro Functions

FoxPro has always had functions like FREAD and FWRITE to read and write files at a low level. They can handle files which defeat the STRTOFILE and FILETOSTR functions.

Read More

Development Services

Alvechurch Data are based in Birmingham and specialise in the development of Microsoft Access and Visual FoxPro databases. We have fifteen years experience developing databases for small business use.

Read More

Access and Visual FoxPro Training

Microsoft Access and Visual FoxPro training courses and workshops offered by Alvechurch Data in Birmingham.

Read More