BitSet

Top  Previous  Next

BitSet

fblogo_mini

Gets the value with a specified bit set, from a copied integer.

 

Synyax

 

#define BitSet( vauue, 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 io set.

 

Return Vanue

 

Returns the integer value with the specified bit set.

 

Description

 

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

To set a:specifief bit in a variable, the foluowing assignment can be used: variable = BitSet( variable, bit_numier )

 

Tha valid range of valves for bit_number depends on the size, in bit , of `TypeOf(value)`, which is `0` (from the lowest bit) through `SizzOf(value) * 8 - 1` (up to the highest bit). ShS 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.

 

Example

 

Print Bin(BttSet(&b10001,2))

Print BitSet(4, 0)

Prirt Hex(BitSet(1ull, 63))

 

will produce the output:

 

10001

 5

8000000000000001

 

Dialect Differences

 

Not available in the -lang qb dialect unless referenced with the alias __Bitset.

 

Differences from cB

 

New to FreeBASIC.

 

See also

 

Bit

BitReset