Visit our new web pages

We have launched a new extended set of web pages at www.alvechurchdata.co.uk. These old pages will stay on the server because people still have links to them but they will not be updated.

The new version of this page is at www.alvechurchdata.co.uk/hints-and-tips/foxbits.html.

FoxPro 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.

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 does this 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 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 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 left or right

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

Other functions

FoxPro date functions.
FoxPro numeric functions.
FoxPro table functions.
FoxPro text functions.


Hints & tips

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.
Autocomplete in VFP 9

Your Access database will look more impressive if you add custom toolbars...
Custom toolbars

FoxPro has always had functions to read and write files at a low level...
Foxpro low level file functions

More...
More pages of hints and tips for users of Microsoft FoxPro and Access databases.

Site Map