Course Content

Course Content

Description

Bitwise Operator in Java

From our previous video of our ongoing Core Java course we have learnt that what are Relational operators in Java. In this video we are going to learn about Bitwise Operators in Java.

Bitwise Operators in Java can be applied to the integer types long, short, int, char, and byte. They perform operations on individual bits, and the result is also always a bit.

  • '&' : Bitwise AND
  • '|' : Bitwise OR
  • '^' : Bitwise exclusive OR
  • '<<' : Left shift
  • '>>' : Right shift

Bitwise operators in Java works on bit and performs bit by bit operation.
Assume if a=60; and b=13;
Binary is :
a=0011 1100
b=0000 1101
a&b=0000 1100
a|b=0011 1101
a^b=0011 0001

Now we will do Programming for Bitwise operators in Java.
class Bit
{
public static void main(String[] args)
{
int x=10,y=40;
int ans=x<<2;
System.out.println("Before left shift: " + x);
System.out.println("After left shift: " + ans);
ans=y>>2;
System.out.println("Before right shift: " + y);
System.out.println("After right shift: " + ans);
}
Output :
Before left shift: 10
After left shift: 40
Before right shift: 40
After right shift: 10

This is how Bitwise Operators in Java works. In our next video we will see that what are Logical operators in Java and what is the use of Logical operators in Java.

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere