Briefly explain bitwise rotation
Briefly explain bitwise rotation
Bit operation is also called a circular shift. This is an operation that is similar to shift but the bits that are at one end are put back to the other end.
This operation will move the bits of the binary object.
OPERATOR | USAGE |
<< | This indicates that the bits are to be shifted to the left. |
>> | This indicates that the bits are to be shifted to the right. |
Consider opr has a value 16.
The bit pattern in 8-bit format is 00010000
So, we will specify the operation as opr << 2
The left operand (opr) specifies the value to be shifted.
The right operand (2) specifies the number of bits the pattern is needed to be shifted.
Both the operands are of the same precedence and are left-to-right associative.
The operands are of int or enum datatype. The operation is performed and the right operand will be converted to the data type int. So, the result will the same type as the left operand.
NOTE:
The right operand should not have a negative value.
The right operand should not be greater than or equal to the width of the bit that is being shifted.
Step by step
Solved in 4 steps