×

C Programs

C Basic & Conditional Programs

C Looping Programs

C String Programs

C Miscellaneous Programs

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

Left Shift Operator (<<) in C

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.

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;
}

Output

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

C Bitwise Operators Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.