Futurebasic/Language/Reference/bit

Bit edit

Function edit

✔ Appearance ✔ Standard ✔ Console

Syntax edit

bitValue = bit( bitPos )

Description edit

This function returns an integer whose binary representation has the bit in position bitPos set to "1", and all other bits set to "0". Bit positions are counted from right to left: a bitPos value of zero corresponds to the rightmost ("least significant") bit. The maximum allowable value for bitPos is 31, which corresponds to the leftmost bit in a long-integer value. bit is useful in conjunction with "bitwise operators" like and and or, for setting and testing the values of particular bits in a quantity.

Example edit

The following expression evaluates as _zTrue (-1) if bit "n" is set in testValue&:

( testValue& and bit( n ) ) <> 0

The following assignment sets bit "n" in testValue& to 1:

testValue& = ( testValue& or bit( n ) )

The following assignment resets bit "n" in testValue& to 0:

testValue& = ( testValue& and not bit( n ) )

Notes edit

If _bitPos is a symbolic constant name, then you can use _bitPos% (note the "%") as a synonym for bit( _bitPos ).

See Also edit

bin$; and; or; not; Appendix C: Data Types and Data Representation

Language Reference