Bitwise Operators — (<<, >>,
~ , &,
|, ^)
number << shift;
number >> shift;
~ number
number & number
number | number
number ^ number
numberAny number,
shiftThe number of bit shifts to perform.
An integer which is the result of the particular operation.
<<, >> return the first argument with a left or right bitshift operation
performed the number of times of the second argument.
~ returns the binary opposite of the
number.
& compares each of the corresponding digits of the two
numbers. If both digits are 1, returns 1 for
that place. Otherwise returns 0 for that place.
| compares each of the corresponding digits of the two
numbers. If either those digits is 1, returns
1 for that place. Otherwise returns 0 for that place.
^ compares each of the corresponding digits of the two
numbers. If both digits are the same, returns
O for that place. If they are different (ie. 0 and 1) returns 1 for that
place.
Gamma>bin(10);0b1010Gamma>bin(10 << 1);0b00010100Gamma>bin(10 >> 1);0b0101Gamma>bin (~10);0b11111111111111111111111111110101Gamma>bin(10);0b1010Gamma>bin (9);0b1001Gamma>bin (9 & 10);0b1000Gamma>bin (9 | 10);0b1011Gamma>bin (9 ^ 10);0b0011Gamma>