C Puzzle 05

Multiply a given number by 2 without using the Multiplication Operator

  • It is possible with the help of the operator << 
  • << is a shift left operator 
  • << is a binary and bitwise operator
  • The Shift Left operator moves every bit of the operand towards the left and the space created at the right side(LSB) will be filled with a zero.

How the shift left operator works?

  • LSB stands for Least Significant bit
  • MSB stands for Most Significant bit

Syntax: 

    Operand = Operand << number of bits to shifted left

Examples:

  x=x<<1   //1 bit of x to be shifted left
  y=y<<2  // 2 bits of y to be shifted left

Note: 

  • Performing the shift left operation for the operand by one time is equal to multiplying the operand by two.

Program









Comments

Popular posts from this blog

Python Tips -06

C Puzzle

Python Tips - 03