int k=5|6|7; how it works ....
int k=4&5&6; how it work .....
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
int k=5|6|7; how it works ....
int k=4&5&6; how it work .....
it's bit-wise operation: OR | and the other AND &
Those are used to represent boolean operators. The && is used for AND statements and the || for OR statements.
The expression "A || B" will return true if either A or B where "A && B" will only return true if both A and B are true.
if(true || false) //code will run if(false || false) //code will not run if(true && false) //code will not run if(true && true) //code will run
Check out my site -> tssolutions.net16.net
Basic OR logic:
x y x&y
--------------
1 0 | 0
1 1 | 1
0 1 | 0
0 0 | 0
In binary the numbers are represented as follow:
4: 100
2: 010
6: 110
The and operator will only return 1 when all 3 bits are 1.
4: 1 0 0
2: 0 1 0
6: 1 1 0
----------
0 0 0
Thus the value of 4&2&6 is zero.
Using the OR operator if only one bit needs to be 1 in order to return 1;
4: 1 0 0
2: 0 1 0
6: 1 1 0
----------
1 1 0
Thus the value of 4&2&6 is 6.
I hope you understand now, otherwise there is another explanation here: Bitwise operators in java
Check out my site -> tssolutions.net16.net