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.

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.

C Bitwise Operators Programs »

Related Programs

Comments and Discussions!

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