Page 165 - ComputerScience_Class_11
P. 165
4. System.out.println(((a+b)>c)? a+b : b-c);
if((a+b)>c)
System.out.println(a+b);
else
System.out.println(b-c);
5. int largest = (n1 >= n2)? ((n1 >= n3)? n1 : n3) : ((n2 >= n3)? n2 : n3);
int largest;
if(n1>=n2)
{
if(n1>=n3)
largest = n1;
else
largest = n3;
}
else
{
if(n2>=n3)
largest = n2;
else
largest = n3;
}
Bitwise Operator
This operator performs bit-level calculations on the operands. The operands can only be byte, short, int and long.
The different types of Bitwise operators are as follows:
Operator Meaning
~ Bitwise Complement
<< Left Shift
>> Right Shift
>>> Unsigned Right Shift
& Bitwise AND
| Bitwise OR (Bitwise Inclusive OR)
! Bitwise NOT
^ Bitwise XOR (Bitwise Exclusive OR)
To work with Bitwise Operators, we need to make a truth table. A truth table is a tabular representation that displays
the input and output bits using bitwise operators like &, | and !. We represent the output in the truth table as true
(1) or false (0), however, the computer means it actually as high or low, which basically means ON or OFF respectively.
Let us see in detail.
a. Bitwise AND (&): When both the results are true, this operator returns true.
st
1 Bit 2 Bit 1 Bit & 2 Bit
nd
nd
st
0 0 0
0 1 0
1 0 0
1 1 1
Variables and Expressions 163

