Skip to content

Bit Operations🔗

See Table 1 for an overview of the available operations for bit processing of numbers. The operands have to be integers.

Table 1: Bit operations
Operation Meaning HALCON operator
lsh(i1,i2) left shift tuple_lsh
rsh(i1,i2) right shift tuple_rsh
i1 band i2 bitwise and tuple_band
i1 bxor i2 bitwise xor tuple_bxor
i1 bor i2 bitwise or tuple_bor
bnot i bitwise complement tuple_bnot

The result of lsh(i1,i2) is a bitwise left shift of i1, which is applied i2 times. If there is no overflow, this is equivalent to a multiplication by \(2^{i2}\).

The result of rsh(i1,i2) is a bitwise right shift of i1, which is applied i2 times. For non-negative i1, this is equivalent to a division by \(2^{i2}\). For negative i1, the result depends on the used hardware.

For lsh and rsh, the result is undefined if the second operand has a negative value or if the value is larger than 32.

More examples can be found in the program bit.hdev.