java | operator is for what?

后端 未结 8 1188
故里飘歌
故里飘歌 2021-01-25 11:14

What is the output of this java code and why ?

 int a = 5 | 3 ;
 System.out.println(a);
8条回答
  •  囚心锁ツ
    2021-01-25 11:49

    This is a bitwise or.

    I did not test it. But it must be 7.

    101 -> 5
    011 -> 3
    ----
    111 -> 7
    
    1|1 = 1
    1|0 = 1
    0|1 = 1
    0|0 = 0
    

提交回复
热议问题