C programming - shift operators

www.i‮fig‬tidea.com

The shift operators in C programming are used to shift the bits of an integer operand to the left or to the right. There are two shift operators in C: the left shift operator << and the right shift operator >>.

Left Shift Operator (<<)

The left shift operator `<<` is a binary operator that is used to shift the bits of an integer operand to the left by a specified number of positions. The general syntax of the left shift operator is:
result = value << n;

where value is the integer operand to be shifted, n is the number of positions to shift the bits, and result is the result of the shift operation.

Here is an example of using the left shift operator:

#include <stdio.h>

int main() {
  int num = 5; // 00000101 in binary
  int result = num << 3; // shift the bits of num to the left by 3 positions

  printf("result = %d\n", result);

  return 0;
}