#20 Operators
#20 Operators
What
* are
operators ?
This indicates what action to
perform
-
What is
*
operand ?
This indicates the items which action has to
apply
-
on on .
* What is expression ?
It consists low
operand and
of operators
-
more 0 or more .
Eg : s + 3
-
S$3 are
operands
-
+ is operator
-
=>
Categories
Of
7
Operators
of
here
I are
categories operators
17 Arithmetic
Operators
·
/(Division)
· -
/Subtraction)
·
+ (Addition
1
%
·
Modulus)
·
*
/Multiplication (
We
already
have
information from mathematics
of
how arithmetic
work
operators .
For
agi-
2) Relational Operators
-
These compares two
operand relation and return true or
false
.
&
== (Equals to ⑧ < (Less than
1
·
= (Not equalstr) · >=
/Greater than or
equals to
& -
(Greater tan) - I Less than or equals to
For
Eg : -
)
3 .
Logical Operators
These combines conditions
two or more and return true ar
false
-
· 11
(Logical OR) Returns true if
-
For Egi-
It
Its seen
*
if one condition is
false ,
will not even evaluate
further
conditions .
4 ) .
Unary Operators
These require only single operand
-
·
++ /Increment)
·
--
(Decrement (
Minus)
(Unary
-
·
+
(Unary Plus)
·
!
·
(Logical NOT)
k-- be used
before after operand.
* + + can or
So
Operand ++ >
Postfix Increment + +
Operand =>
Prefix Increment
E
Operand --
=>
Postfix Decrement --
the value
value .
itdo it'll
it'll
change false Bif the current value is
false ,
change the
value to true
.
For
Egi-
5.
)
Assignment Operators
-
G
- ·
*
·
+ I · I =
6 - I · % =
avariable (on
left side of the
operator
For
Eg : -
6) Bitwise Operator
These works bits i < 1 and 0 and are
very fast
.
-
on .
·
&(Bitwise AND)
·
1( Bitwise OR)
·
n) Bitwise XOR)
~
· (Bitwise NOT
a b a b a b
O 0 = 0 g O
=> O O O => s
01 = O O I => I G I
>
-
-
I
I 0 = 0 I G => I ( 8 => I
I 1 - 1 I > I I
-
I - I => o
-
tor
Eg : -
So 0 = 1
1 = 6
Let's
compute
-y
(NoTg4)
its we know in Java numbers are
signed i . e Most
Significant Bit
& do 2
20
it is
(MSB) Since MsBisO so
positive .
-
3
22
I
O
2 2 2
( ) I
-
-
(MSB3)
Since MSBistie result is-he value
of negative
,
so the MSB will be
decimal
Now
converting it to
gives
us
-
8 + 0 + 2 + 1
i .
e
-
So 0100 ---
> -0100 = 101
We calculate it (N + 1)
directly using formula
can the -
.
So in o u r case
it'll be (n + 1) ie .
5
=
-
is
confirm if-5 have
* How can we 101
To 2
get
5 we know that we to
find its
Complement
-
-
So
for 4 ie 0101
.
i e 1010 + 1 => 1011
·
/Signed Left Shift
· (Signed Right Shift
·
*: Its
signed right shift
It
fills the most significant bit with the
sign of
the number
-
Eg : -
1) 11000116's 7 will be
11100011
em
shifted
↓
right
MSB added as same
sign original
of
the number
2) 01000110's 77 will be
· 010 0 0 11
-
shifted right
MSB added as same
sign of
the
original number
It's
* >> :
unsigned right shift
It
fills with
the MSB the O :
-
/1000110's
Eg : 1) > will be
O 1 10 0 0 11
-
shifted right
MSB
filled with o
el 0 1000110's will be
00100011
-
I shifted
MSB
right
added O
as
Demo for born
left right shift :-
For
*
Left Shift LSB will
always filled with 0
.
*
Left Shift once doubles the number
*
RightShift once halves the number
-
don't have value
of
* There is no sense <LL as LSB
any
8)
Ternary Operators
It mimics the condition
if else
-
(condition)
? Expression 1 : Expression 2
-
For
Egi-
a)
Type Comparison Operator
It is used to do the check particular object is
type whether
of
-
a
,
certain class .
or not
instance
Of
-
For
Egi-
have precedence
Associativity If
I operators
: the same then it is evaluated
-
based on its
associativity /Left Ju
Right or
Right to
Left).
High
Priority
Low
* Let's solve an
example expression
inta = 4
Solve a = a + a+ + + ++ a + - -
a + a --
a = 45054
.. a = 4 + 4 + 6 * 5 + 5
a = n + y + 30 + 5
a = 39