0% found this document useful (0 votes)
3 views11 pages

Bitwise Logical Operators Explained

Uploaded by

karthi376438
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

Bitwise Logical Operators Explained

Uploaded by

karthi376438
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Bitwise Logical Operators

 Bitwise Unary NOT { ~ }


 Bitwise AND { & }
 Bitwise OR { | }
Unary NOT [ ~ ]

Bitwise Unary NOT is also called


bitwise Complement.

It is Unary Operator because it operates


on single Operand.

It inverts all of the bits of its operand.


Example : Unary Not Operator
class BitwiseNOT{

public staticvoidmain(String args[]){

[Link]("~ 0 = "+ ~0);


[Link]("~ 1 = "+ ~1);
[Link]("~ 2 = "+ ~2);
[Link]("~ 3 = "+ ~3);
[Link]("~ 4 = "+ ~4);
[Link]("~ 5 = "+ ~5);
[Link]("~ 6 = "+ ~6);
[Link]("~ 7 = "+ ~7);
[Link]("~ 8 = "+ ~8);
[Link]("~ 9 = "+ ~9);
}
}
Output :
~0=-1
~1=-2
~2=-3
~3=-4
~4=-5
~5=-6
~6=-7
~7=-8
~8=-9
Bitwise AND Operators [ & ]
Bitwise AND Operator table

A B A&B
0 0 0
0 1 0
1 0 0
1 1 1
Example : AND ing 42 and 15
class BitwiseAND{
public static void main(String args[]){

int num1 =42;


int num2 =15;

[Link]("Result="+(num1&num2));
}
}
Output :
Result = 10
 42 in Binary format is ->00101010
 15 in Binary format is ->00001111
 As per table we get ->00001010
 println method will print decimal
equivalent of 00001010 ( that is 10).
Bitwise OR Operators [ | ]
Bitwise OR Operator table

A B A&B
0 0 0
0 1 1
1 0 1
1 1 1
Example : OR ing 42 and 15
class BitwiseOR{
public static void main(String args[]){

int num1 =42;


int num2 =15;

[Link]("Result="+(num1|num2));
}
}
Output :
Result = 47
 42 in Binary format is ->00101010
 15 in Binary format is ->00001111
 As per table we get ->00101111
 println method will print decimal
equivalent of 00101111 ( that is 47)

You might also like