Jump to content

Futurebasic/Language/Reference/bit

From Wikibooks, open books for an open world

Function

[edit | edit source]

✔ Appearance ✔ Standard ✔ Console

Syntax

[edit | edit source]
bitValue = bit( bitPos )

Description

[edit | edit source]

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 | edit source]

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 | edit source]

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

See Also

[edit | edit source]

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

Language Reference