IHYPRESS.NET > C PROGRAMMING
HOME | ASP | C | HTML/CSS | JAVASCRIPT | MATLAB | PERL | PHP | PYTHON | RUBY
C > 11. Bitwise Operators
>
 
/* The left shift bitwise operator */
#include <stdio.h>
 
int
main (void)
{
    unsigned a=64, b=25, c=1, d=100;

    printf ("%4d << 1 = %4d (%3x HEX)\n", a, a<<1, a<<1);
    printf ("%4d << 1 = %4d (%3x HEX)\n", b, b<<1, b<<1);
    printf ("%4d << 1 = %4d (%3x HEX)\n", c, c<<1, c<<1);
    printf ("%4d << 1 = %4d (%3x HEX)\n", d, d<<1, d<<1);
    printf ("%4d << 2 = %4d (%3x HEX)\n", a, a<<2, a<<2);
    printf ("%4d << 3 = %4d (%3x HEX)\n", b, b<<3, b<<3);
    printf ("%4d << 4 = %4d (%3x HEX)\n", d, d<<4, d<<4);
    printf ("%4d << 5 = %4d (%3x HEX)\n", d, d<<5, d<<5);

    return(0);
}
Legend: preprocessor directives | variable declarations | main program | helper functions
user-defined structures | comments
  64 << 1 =  128 ( 80 HEX)
  25 << 1 =   50 ( 32 HEX)
   1 << 1 =    2 (  2 HEX)
 100 << 1 =  200 ( c8 HEX)
  64 << 2 =  256 (100 HEX)
  25 << 3 =  200 ( c8 HEX)
 100 << 4 = 1600 (640 HEX)
 100 << 5 = 3200 (c80 HEX)
COPYRIGHT © 2019 IHYPRESS.NET. A DIVISION OF IHY PRESS, KIRKLAND, WA 98083 USA. ALL RIGHTS RESERVED.
SHARE!