BitSet
 
Macro that sets a bit in an integer

Syntax

#define BitSet( value, bit_number ) ((value) Or (Cast(TypeOf(Value), 1) Shl (bit_number)))

Usage

result = BitSet(value, bit_number)

Parameters

value
The integer value to set a bit in. It is not modified.
bit_number
The zero-based number of the bit to set; 0 is the least-significant bit. The valid range for this number is 0 to 31, unless value is a LongInt, in which case the range is from 0 to 63.

Return Value

value with bit bit_number set to 1.

Description

Macro returning value with the bit bit_number set to 1.
foo = BitSet( bar, 5 ) does the same as foo = bar or (1 shl 5).

Example

Print BitSet(4, 0)
Print Hex(BitSet(1ull, 63))

will produce the output:

 5
8000000000000001

Dialect Differences

  • Not available in the -lang qb dialect.

Differences from QB

  • New to FreeBASIC.

See also