This program will demonstrate example of Right Shift (>>) Operator in C programming language. Using this program we will show how to perform right shift operation using C program.
/* C Program to demonstrate example right shift (>>) operator.*/
unsigned int num = 0xff;
printf("\nValue of num = %04X before right shift.", num);
/*shifting 2 bytes right*/
num = (num >> 2);
printf("\nValue of num = %04X after right shift.", num);
Value of num = 00FF before right shift.
Value of num = 003F after right shift.
Right Shift Operator (>>) is a bitwise operator, which perform operation on bits. It is used to shift given number of bytes in the right and inserts 0’s in the left.
Binary of 0xFF in (in 4 bytes format) - 0000 0000 1111 1111.
After 2 bytes right shift (in 4 bytes format) – 0000 0000 0011 1111, which is equivalent of 0x003F.
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.