Skip to content

Instantly share code, notes, and snippets.

@gwpantazes
Created June 16, 2017 15:44
Show Gist options
  • Save gwpantazes/e7b79700c5851d4de5675c34df082d42 to your computer and use it in GitHub Desktop.
Save gwpantazes/e7b79700c5851d4de5675c34df082d42 to your computer and use it in GitHub Desktop.
Java Bitwise Operators work as logical operators: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.22.2
// https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.22.2
class BitwiseOperatorAsLogicalTest {
public static void main(String[] args)
{
System.out.println("Bitwise AND operator still works as logical.");
System.out.println(true & true);
System.out.println(true & false);
System.out.println(false & true);
System.out.println(false & false);
System.out.println("Bitwise OR operator still works as logical.");
System.out.println(true | true);
System.out.println(true | false);
System.out.println(false | true);
System.out.println(false | false);
System.out.println("Bitwise XOR operator still works as logical.");
System.out.println(true ^ true);
System.out.println(true ^ false);
System.out.println(false ^ true);
System.out.println(false ^ false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment