Professional Documents
Culture Documents
Cha 2 PCI
Cha 2 PCI
33=1
‘Assuming the data to be char i.e. 8 bit data
(23)o= (00001011),
After shifting left once (00000101)
‘After shifting left for the second time
(00000010,
‘After shifting for the third time
(00000001);= (thotor
Programming in‘: (MSBTE) =< Sa Temary/Conditional OPerat
fhe ORefSand9uI3 = :
The EXOR ofS and9is12 0 = onaltional operator with
The NOT Sis—6 aoe .
[The NOT of 9 is — 10
2.8.2(C) Logical operators
~ _{peical operators follow the same truth table as forthe
bitwise operators; but they are used to check
Conditions instead of performing operations on a data.
— The logical operators are AND and OR. The a
used for these operators in C are && and |
respectively.
For example a statement
yPS&RKy<10; will result in “true” ie. 1 if the value of
Vis greater than 5 AND less than 10, else it will result
infalsei.eo.
Another example a statement
W511 y=2;
will result in “true” ie. 1 if the value of y is greater
than 5 OR equal to 2, else it will result in false ie. 0.
28.2(D) Relational operators
— The relational operators are used to test the relation
‘between two variables or a variable and constant.
~The operators like ‘< (less than) and ‘>’ (greater than)
Used in the above examples are relational operators.
We have seen the example also of the “==” (equality
‘perator) in the above logical operators,
Allist ofall the relational operators is as follows :
+ == used to check if the two things are
equal,
2 I= used to check ifthe two things are not
equal,
3 < Used to check ifthe first data is less
than the second one.
4, > Used to check if the fist data 's greater
than the second one,
< tsed to check if the first data is less
than or equal to the second one,
fh? t0 check ifthe first data is greater
than or equal to the second one’
The examples of these relational operators are aq
m with the logical operators above,
6.
erator that requires three operand i calle
‘An op
ternary operator:
in C. This 9
nly one ternary operator
is oneck a condition and accordingly do
the two things based on the condition being
false :
‘The syntax(way of writing) of this operator is a fg
He
— Hence; as shown in the syntax, first the condition
be written in brackets followed by a question
be performed if the condition is false.
Example :
given condition i.e. x > y is true. Else; the
will be put into z. Hence, the value of the
variable will be put into z.
~ Aslightly complicated use of this operator is to
greatest of three numbers as shown in the exa
This statement will
the variable g.
2.8.4 Assignment Operators and State i
~ These operators are used to assign the value
expression or variable on the right of the
Operator to the variable on its left.
The simple assignment operator is ‘<'. But
some more assignment. Operators called as com
assignment operators,
‘expression or vay
the variable on its left.
Example: yaxs,4= 4 This operator adds. ie
is opaator nds halve Wefan oa, ans thi pseton anD> the VaR: its left
right and the result is put into the v
ue put into the variable on and right. and the result #5 put into ed
variable on its left.
Example : yB=x; Is same as Y=VE%
Example : y+=x; Is same as y=¥+X;
variables on its!
This operator ORs the jeft and
= : This operator subtracts the variable on its 8.
right from the variable on its left. and right and the result is putinto the variable of
the result is put into the variable on its left. ae
Example : =x (5. same asy=y—%) Example :y|=%; is same a5 ¥-¥)
4g. me This operator ©xORs the variables on GF
uit into the
and right and the result isp!
variable on its left.
Example : y*=x; is same as Y=¥"%
1 shifts in left direction the
1e number of times
‘or value on right
the variable on its
2: This operator multiplies the variable on its left
‘and right and the result is put into the
variable on its left.
i 10,