setbit(
NUMBER
,
BIT
,
TRUEFALSE
)

The setbit( function sets or clears one bit within a number, without disturbing any of the other bits.


Parameters

This function has three parameters:

number – the initial integer value.

bit – the bit to flip, from 1 to 64.

truefalse – specifies whether to set (true() or -1) or clear (false() or 0) the bit.


Description

This function sets or clears one bit within a number, without disturbing any of the other bits. The bit number may be from 1 to 64 and is counted backwards from the last bit. The bit will be set based on the true/false parameter - set if true, cleared if false.

radixstr("binary",setbit(16,3,true())) ☞ 00010100
radixstr("binary",setbit(31,4,false())) ☞ 00010111

Note: This function is equivalent to:

(thenum and onescomplement(bit(bitnum))) + (bit(bitnum) and truefalse)

See Also


History

VersionStatusNotes
10.0UpdatedCarried over from Panorama 6.0, but now supports up to 64 bits (instead of 32).