Q:

C program to demonstrate example of right shift (>>) operator

0

C program to demonstrate example of right shift (>>) operator.

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.

 

All Answers

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

Example of Right Shift (>>) Operator in C program

/* C Program to demonstrate example right shift (>>) operator.*/

#include <stdio.h>

int main()
{

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

    return 0;
}
    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.

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