Why is java int allowed to use the | operator ? How does it evaluate? -


i tried compiling , running following code

public static void main(string... args) {     int x = 1 | 2 | 3 | 4;     //int x = 1 | 1 | 1 ;     //int x = 1 | 2 ;     //int x = 2 | 1 ;     system.out.println(x); } 

i tried in dot net , not working how come working in java ?? how code being evaluated produce answer ??

that called bitwise operator in java. operates on bits of operands.the bitwise | operator performs bitwise inclusive or operation.

if observer lower order bits :

1 - 0001 2 - 0010 3 - 0011 4 - 0100 

biwise or of each of them produce 0111 7.you can refer jls 15.22.1 more.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -