I am going through a tutorial where so far it gives you the code below:
boolean p, q;
System.out.println("P\tQ\tAND\tOR\tXOR\tNOT");
p = true; q = true;
System.out.print(p + "\t" + q + "\t");
System.out.print((p&q) + "\t" + (p|q) + "\t");
System.out.println((p^q) + "\t" + (!p));
p = true; q = false;
System.out.print(p + "\t" + q + "\t");
System.out.print((p&q) + "\t" + (p|q) + "\t");
System.out.println((p^q) + "\t" + (!p));
p = false; q = true;
System.out.print(p + "\t" + q + "\t");
System.out.print((p&q) + "\t" + (p|q) + "\t");
System.out.println((p^q) + "\t" + (!p));
p = false; q = false;
System.out.print(p + "\t" + q + "\t");
System.out.print((p&q) + "\t" + (p|q) + "\t");
System.out.println((p^q) + "\t" + (!p));
The task is to modify the program so that it uses 1's and 0's instead of true and false.
Im not sure if this is ment to be done by Casting Incompatible Types but I think that is the way to go as that is the section before it.
Can anyone give some advice and explanation as to why it works?
This is not what the tutorial asks you to do. I think they want you to literally replace
booleanwithint,truewith1, andfalsewith0, like this:This will lead you to understanding of bitwise operations on integers
0and1.