Q:

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

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now