Bit
 
Macro that returns the value of one bit of an integer

Syntax

#define Bit( value, bit_number ) (((value) And (Cast(TypeOf(Value), 1) Shl (bit_number))) <> 0)

Usage

result = Bit(value, bit_number)

Parameters

value
Value in which to test the bit.
bit_number
Zero-based number of the bit to test, where 0 is the least-significant bit.

Return Value

-1 if bit bit_number is set in value, else 0.

Description

Bit returns -1 if the bit bit_number of value is 1, returns 0 if bit is 0.

foo = Bit( bar, 10 ) is the same as foo = (bar and 1 shl 10) <> 0.

Example

Print Bit(4,2)
Print Bit(5,1)
Print Bit(&H8000000000000000ULL,63)

will produce the output:

-1
0
-1

Dialect Differences

  • Not available in the -lang qb dialect.

Differences from QB

  • New to FreeBASIC

See also