C Bitwise Right Shift : (>>) Operator
In the previous chapter we have learnt about Bitwise Left Shift Operator. In this chapter we are looking into Bitwise Right Shift Operator.
Contents
Bitwise Right Shift Operator in C
- It is denoted by >>
- Bit Pattern of the data can be shifted by specified number of Positions to Right
- When Data is Shifted Right , leading zero’s are filled with zero.
- Right shift Operator is Binary Operator [Bi - two]
- Binary means , Operator that require two arguments
Quick Overview of Right Shift Operator
Original Number A | 0000 0000 0011 1100 |
Right Shift by 2 | 0000 0000 0000 1111 |
Leading 2 Blanks | Replaced by 0 ,Shown in RED |
Direction of Movement of Data | Right ========>>>>>> |
Syntax :
[variable]>>[number of places]
Live Example : Bitwise Operator [Right Shift Operator]
#include<stdio.h> int main() { int a = 60; printf("\nNumber is Shifted By 1 Bit : %d",a >> 1); printf("\nNumber is Shifted By 2 Bits : %d",a >> 2); printf("\nNumber is Shifted By 3 Bits : %d",a >> 3); return(0); }
Output :
Number is Shifted By 1 Bit : 30 Number is Shifted By 2 Bits : 15 Number is Shifted By 3 Bits : 7