Last updated 3 months ago

The left-shift operator causes the bits in the left value (either a variable or a literal)to be shifted to the left by the number of positions specified by the bits in the right value.

with console from std:iovar a = 20 << 2console->out:a //Output: 80

The right-shift operator causes the bits in the left value (either a variable or a literal)to be shifted to the right by the number of positions specified by the bits in the right value.

with console from std:iovar a = 8 >> 2console->out:a //Output: 2

The result of the bitwise and (denoted by `&`

) is 1 if the corresponding bits of two operands are 1. If either bit of an operand is 0, the result of corresponding bit is evaluated to 0.

with console from std:ioâ€‹var a = 12 //00001100 in binaryvar b = 25 //00011001 in binaryâ€‹console->out:a&b //Output: 8

The result of the bitwise or (denoted by `|`

) is 1 if at least one corresponding bit of two operands is 1.

with console from std:ioâ€‹var a = 12var b = 25â€‹console->out:a|b //Output: 29

The result of the bitwise xor (denoted by `^`

) is 1 if the corresponding bits of two operands are opposite.

with console from std:ioâ€‹var a = 12var b = 25â€‹console->out:a^b //Output: 21

The bitwise complement (denoted by `~`

) changes 1 to 0 and 0 to 1.

with console from std:ioâ€‹var a = 35 //00100011 in binaryâ€‹console->out:~a //Output: 220

â€‹