bitorch_engine.utils.quant_operators.bit_set

bitorch_engine.utils.quant_operators.bit_set(var, pos, val)[source]

Sets a specific bit in an integer variable to a given value.

This method allows you to modify a single bit within an integer by shifting the val (either 0 or 1) to the position pos and then performing a bitwise OR operation with the original variable var. This effectively sets the bit at position pos to the value specified by val.

The operation performed is equivalent to: var |= (val << pos)

Parameters:
  • var (int) – The original integer variable whose bit is to be modified.

  • pos (int) – The position of the bit to be set, starting from 0 for the least significant bit (LSB).

  • val (int) – The new value for the bit, either 0 or 1.

Returns:

The modified integer with the bit at position pos set to val.

Return type:

int

Example

>>> bit_set(0b0010, 1, 1)
6  # The binary representation is 0b0110