BitSet

FreeBASIC

BitSet
 
Gets the value of an integer with a specified bit set.

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.
bit_number
The index of the bit to set.

Return Value

Returns the integer value with the specified bit set.

Description

This macro expands to a copy of the integer value with the specified bit_number set (to on, or `1`). Behaves as `value Or (1 Shl bit_number)`.

The valid range of values for bit_number depends on the size, in bits, of `TypeOf(value)`, which is `0` through `SizeOf(value) * 8 - 1`. See Standard Datatype Limits for a table of the standard datatypes and their sizes.

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 unless referenced with the alias __Bitset.

Differences from QB

  • New to FreeBASIC.

See also