< Futurebasic < Language < Reference

Bit

Function

✔ Appearance ✔ Standard ✔ Console

Syntax

bitValue = bit( bitPos )

Description

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

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

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

See Also

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

Language Reference

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.