Someone to explain what this prints

0

Someone is kind enough to explain to me what these two lines of code print in java:

System.out.println(5&6)
System.out.println(2|1)
    
asked by Daniel Cano 02.06.2017 в 23:00
source

1 answer

3

They are bit-level operators, for example:

int a = 5;  //a = 101
int b = 6;  //b = 110

System.out.println(a&b); //4=100
System.out.println(a|b); //7=111

what it does is take the number 0 as false and 1 with true and complete the operation with the logical operator that you place.

AND or &: needs both true (1) to be true (1).

OR or |: You need one of the two to be true (1) for the operation to be true.

    
answered by 02.06.2017 / 23:17
source