Shift Operators:
- These operators are used to shift binary bits either to Left or Right
- The operators are,
- Left Shift (<<)
- Right Shift(>>)
Theoretical formulas:
- For Right Shift: n/2s
- For Left Shift: n*2s
- Where ‘n’ is the data and ‘s’ is the number of bits to shift
Right Shift operator(>>):
int main() { int x=32; int y=x>>2; printf(“y val : %d\n”, y); return 0; } | 32/22 32/4 8 |
Left Shift operator(<<):
int main() { int x=2; int y=x<<3; printf(“y val : %d\n”, y); return 0; } | 2*23 2*8 16 |