Bit Operations

Work at the bit level. For certain low-level tasks.

Operator Description
~ Bitwise negation. Negate all the bits in a number.
<< Left bitwise shift. Shift all bits in a number to the left.
>> Right bitwise shift. Shift all bits in a number to the right.
& Bitwise AND. Perform AND operation on all bits in two numbers.
` `
^ Bitwise XOR. Perform an exclusive OR operation on all bits in two numbers.

Note that there are also corresponding assignment operators (for example, <<=) for all but bitwise negation.

# produce a list of powers of 2 using left bitwise shift operator
[me@linuxbox ~]$ for ((i=0;i<8;++i)); do echo $((1<<i)); done
1
2
4
8
16
32
64
128