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.
/* C Program to demonstrate example of left shift (<<) operator.*/
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);
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.
total answers (1)
start bookmarking useful questions and collections and save it into your
own study-lists, login now to start creating your own collections.