- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the main shift operators provided by Java? Explain with an example?
Java provides three shift operators namely −
Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.
Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.
Shift right zero fill operator. The left operands value is moved right by the number of bits specified by the right operand and shifted values are filled up with zeros.
Example
public class Test { public static void main(String args[]) { int a = 60;/* 60 = 0011 1100 */ int b = 13;/* 13 = 0000 1101 */ int c = 0; c = a << 2; /* 240 = 1111 0000 */ System.out.println("a << 2 = " + c ); c = a >> 2; /* 15 = 1111 */ System.out.println("a >> 2 = " + c ); c = a >>> 2; /* 15 = 0000 1111 */ System.out.println("a >>> 2 = " + c ); } }
Output
a << 2 = 240 a >> 2 = 15 a >>> 2 = 15
- Related Articles
- Java Shift operators
- What are Left Shift and Right Shift Operators (>> and
- What are shift operators in C++?
- What are polygons ? Explain with an example.
- What are isobars? Explain with an example.
- What are jagged arrays and explain with an example in Java?
- What are the bitwise zero fill right shift zero operators in Java?
- What are the services provided by an OS with multiple users?
- What is Inheritance in Java? Explain with an example
- What is shallow copy? Explain with an example in Java.
- What is deep copy? Explain with an example in Java.
- What is an anonymous array and explain with an example in Java?
- What do you mean by free fall? Explain with an example.
- What is overriding in Java can explain briefly with an example?
- What is meant by Splicing an array in JavaScript? Explain with an example

Advertisements