Demonstrating the shift operators. - C Operator

C examples for Operator:Bit Operator

Description

Demonstrating the shift operators.

Demo Code

#include <stdio.h>

int main( void )
{
     unsigned int y, x = 255;
     int count;/*from  w w  w .  j a  v a  2 s.co m*/

     printf("Decimal\t\tshift left by\tresult\n");

     for (count = 1; count < 8; count++)
     {
         y = x << count;
         printf("%d\t\t%d\t\t%d\n", x, count, y);
     }
     printf("\n\nDecimal\t\tshift right by\tresult\n");

     for (count = 1; count < 8; count++)
     {
          y = x >> count;
          printf("%d\t\t%d\t\t%d\n", x, count, y);
     }
     return 0;
}

Result


Related Tutorials