/* A illustration of shift operator in C */
/* Sachidananda Urs */
/* Sat Dec 27 22:39:10 IST 2008 */

/* Right Shift:
 * Shifting right by n bits on an unsigned binary number has the effect of
 * dividing it by 2n (rounding towards 0).
 *
 * Left Shift:
 * Shifting left by n bits on a signed or unsigned binary number has the
 * effect of multiplying it by 2n.  
 */

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int
main(int argc, char **argv)
{
  long oper, operand;
  char *progname = argv[0];

  if (argc != 3) {
    fprintf(stderr, "Usage: %s operator operand\n", progname);
    exit(1);
  }

  oper = strtol(argv[1], (char **)NULL, 10);
  operand = strtol(argv[2], (char **)NULL, 10);
  
  printf("Right shift of %ld is %d\n", oper,(int) (oper >> operand));
  printf("Left shift of %ld is %d\n", oper, (int) (oper << operand));
  return(0);
}
