Skip to content

BITSET


Gets the value with a specified bit set, from a copied 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.

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).

To set a specified bit in a variable, the following assignment can be used: variable = Bitset( variable, bit_number )

The valid range of values for bit_number depends on the size, in bits, of Typeof(value), which is 0 (from the lowest bit) through Sizeof(value) * 8 - 1 (up to the highest bit). See Standard Datatype Limits for a table of the standard datatypes and their sizes.

For the bit_number values outside the valid range, the results of this macro are undefined.

Examples

start GeSHi

vb
Print Bin(BitSet(&b10001,2))
Print BitSet(4, 0)
Print Hex(BitSet(1ull, 63))

end GeSHi

will produce the output:

10101
 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

  • Bit
  • Bitreset

Back to DocToc

Translated from FreeBASIC official docs. Contact us for removal if infringed.
FreeBASIC is an open-source project, not affiliated with Microsoft