Home » C programs » C programs on Bitwise Operators

C program to demonstrate example of left shift (<<) operator.

This program will demonstrate example of Left Shift (<<) Operator in C programming language. Using this program we will show how to perform left shift operation using C program.

Example of Left Shift (<<) Operator in C program

    /* C Program to demonstrate example of left shift (<<) operator.*/
    #include <stdio.h>

    int main()
    {
 
	    unsigned int num= 0xff;

	    printf("\nValue of num = %04X before left shift.",num);

	    /*shifting 2 bytes left*/
	    num = (num<<2);
	    printf("\nValue of num = %04X after left shift.",num);

	    return 0;
    }

    Value of num = 00FF before left shift.
    Value of num = 03FC after left shift.

Left Shift Operator (<<) is a bitwise operator, which perform operation on bits. It is used to shift given number of bytes in the left and inserts 0’s in the right.
Binary of 0xFF in (in 4 bytes format) - 0000 0000 1111 1111.
After 2 bytes left shift (in 4 bytes format) – 0000 0011 1111 1100, which is equivalent of 0x03FC.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.