Bitwise Operators

The bitwise operators are as follow:

& Bitwise AND

! Bitwise OR

^ Bitwise exclusive OR (XOR)

~ Bitwise complement

Syntax:

N value_1 & N value_2
value_1 ! N value_2
N value_1 ^ N value_2
~Y value

 

Return Value:

Y result

 
Precedence:8 (&), 7(!, ^),9 (~)
Description:

Use these operators for operating on numbers which are treated as a binary number. Where devices are selected according to the bits of a number, the use of these operators allows one bit to be changed without affecting the other bits

You can also use the operators AND, OR, XOR and NOT in place of the symbols above, but AND, OR and NOT, (but not XOR) have a differentprecedences (3, 2, and 4 respectively)

 

Example:


13 & 3 = 1
131 ! 3 = 15
13 ^ 03 = 14
~13 = 4294967282