setbit(
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

- bit( -- converts a bit number (1 to 64) into a number (1, 2, 4, 8, 16, etc.)
- getbit( -- returns the value of a bit within a number.
- onescomplement( -- returns the one's complement of a 64 bit number (all bits are reversed)

History

Version | Status | Notes
10.0 | Updated | Carried over from Panorama 6.0, but now supports up to 64 bits (instead of 32).