Tuesday, October 15, 2013

Basic Operators

Insurance Loans Mortgage Attorney Credit Lawyer Donate Degree Hosting Claim Conference Call Trading Software Recovery Transfer Gas/Electricity Classes Rehab Treatment Cord Blood

The Bitwise Operators:

Java defines several bitwise operators, which can be applied to the integer types, long, int, short, char, and byte.

Convert Number to Binary 




60 ------- 00111100
13 ------- 00001101

Operator Description Example
& Binary AND Operator copies a bit to the result if it exists in both operands 60 & 13 = 0000 1100
| Binary OR Operator copies a bit if it exists in either operand 60 | 13 = 0011 1101
^ Binary XOR Operator copies the bit if it is set in one operand but not both 60 ^ 13 = 0011 0001
~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. ~a = 1100 0011

The Logical Operators:


Operator Description Example
&& Called Logical AND operator. If both the operands are non-zero,
then the condition becomes true.
(false && true) is false
(true && true) is true
|| Called Logical OR Operator. If any of the two operands are non-zero,
then the condition becomes true.
(false || true) is true
(false || false ) is false
! Called Logical NOT Operator. Use to reverses the logical state of its operand.
If a condition is true then Logical NOT operator will make false.
(!true) is false
(!false) is ture

No comments:

Post a Comment