Brian Dunning's FileMaker Custom Functions

BitTest ( value ; bit )

Checks if bitnumber 'bit' in value 'value' is on or off

  Average rating: 4.2 (37 votes) Log in to vote

Theo Ros   Theo Ros
*
http://notapplicable.com

Share on Facebook Share on Twitter

  Sample input:
BitTest ( 33 , 5 )
  Sample output:
True

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Checks if bitnumber 'bit' in value 'value' is on or off
The first bitnumber in a value is 0
For a value = 1, bitnumber 0 is ON
For a value = 2, bitnumber 0 = OFF, bitnumber 1 = ON

Syntax: BitTest ( value ; bit )
Returns True (1) if the bit is ON, False (0) if not.

Return type: Number (boolean)

This function is a vital part of the BitSet(), BitClear() and BitChange() functions.

 

Comments

Leland Long   Leland Long, Charleston, SC, USA
Apr 1, 2014
Appears to fail after at least 4 bits. Here's a test to see the failure:

Let ( [
binary = "01101101" ;

bit0 = BitTest ( binary ; 0 ) ;
bit1 = BitTest ( binary ; 1 ) ;
bit2 = BitTest ( binary ; 2 ) ;
bit3 = BitTest ( binary ; 3 ) ;
bit4 = BitTest ( binary ; 4 ) ;
bit5 = BitTest ( binary ; 5 ) ;
bit6 = BitTest ( binary ; 6 ) ;
bit7 = BitTest ( binary ; 7 ) ;
bit8 = BitTest ( binary ; 8 ) ] ;

bit8 & bit7 & bit6 & bit5 & bit4 & bit3 & bit2 & bit1 & bit0
)

This results in: 100101101
 
Leland Long   Leland Long, Charleston, SC, USA
Apr 1, 2014
Wow! I need more coffee…..
I see now that the input is assuming a decimal number, not a binary number or string.
False alarm!
 
Theo Ros   Theo Ros, Hilversum, The Netherlands
Apr 1, 2014
Yes, the 'value' parameter is meant to be a decimal number. Sorry i have not made that clearer in the description.

Cheers,
Theo
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Under construction. Email me your wish list for improvements.