Wiki source for KeyPgBitset


Show raw source

{{fbdoc item="title" value="BITSET"}}----
Gets the value of an integer with a specified bit set.

{{fbdoc item="syntax"}}##
[[KeyPgPpdefine|#define]] **Bitset**( //value//, //bit_number// ) ((//value//) [[KeyPgOpOr|or]] ([[KeyPgCast|Cast]]([[KeyPgTypeof|TypeOf]](//Value//), 1) [[KeyPgOpShiftLeft|shl]] (//bit_number//)))
##
{{fbdoc item="usage"}}##
//result// = **Bitset**( //value//, //bit_number// )
##
{{fbdoc item="param"}}
##//value//##
The integer value.
##//bit_number//##
The index of the bit to set.

{{fbdoc item="ret"}}
Returns the integer value with the specified bit set.

{{fbdoc item="desc"}}
This macro expands to a copy of the integer ##//value//## with the specified ##//bit_number//## set (to //on//, or `##1##`). Behaves as `##//value// [[KeyPgOpOr|Or]] (1 [[KeyPgOpShiftLeft|Shl]] //bit_number//)##`.

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

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/bits/bitset.bas"}}%%(freebasic)
print bitset(4, 0)
print hex(bitset(1ull, 63))
%%
will produce the output:

%% 5
8000000000000001
%%

{{fbdoc item="lang"}}
- Not available in the //[[CompilerOptlang|-lang qb]]// dialect unless referenced with the alias ##**""__Bitset""**##.

{{fbdoc item="diff"}}
- New to ""FreeBASIC"".

{{fbdoc item="see"}}
- ##[[KeyPgBit|Bit]]##
- ##[[KeyPgBitreset|Bitreset]]##

{{fbdoc item="back" value="CatPgBits|Bit Manipulation"}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode