Relation Operators
A relation operator is used for comparing two values it returns 1 if the relation is true and 0 if relation is false.For eg if you want to check that you are adult or not then we can se use comparison operator to check whether the entered age is greater than 17 or not 'age>17'.
Output:
Logical Operators
An expression containing logical operator returns either 0 or 1 depending upon whether expression results true or false.It is mostly used in decision making. This type of operators are used when we want to check multiple condition simultaneously.
1]&&:logical AND operators are used when we want to check multiple condition simultaneously.all the condition will return boolean value(1 0r 0),if all the condition return true(1) then it will become true otherwise false.Basically in background multiplication is performed.
- 1 X 0 = 0 False
- 0 X1 = 0 False
- 0 X 0 = 0 False
- 1 X 1= 1 True
To remember the concept of logical AND we have to simply multiply all boolean values returned from conditions and after multiplication of all boolean if the result is 1 then we can say that the final result is true.
Let's understand with an example.
Output
In above eg,We have used logical AND(&&)operator in which if both of the condition is satisfied then only it will become true.
2] | |:logical OR operators are used when we want to check multiple condition simultaneously.all the condition will return boolean value(1 0r 0),if any of the condition return true(1) then it will become true otherwise false.Basically in background addition is performed.
- 1 + 0 = 1 True
- 0 +1 = 0 True
- 0 + 0 = 0 False
- 1 + 1= 1 True
To
remember the concept of logical OR we have to simply ADD all boolean
values returned from conditions and after addition of all boolean
if the result is 1 then we can say that the final result is true.
Let's understand with an example.
Output
In above eg,We have used logical OR(||)operator in which if anyone of the condition is satisfied then it will become true.
3]!:logical NOT operator is used to invert(opposite) the result.for eg if the result is true then it will become false if we have used logical NOT.
- !1=0
- !0=1
Output
Bitwise Operator
During computation, mathematical operations like: addition,
subtraction, multiplication, division, etc are converted to bit-level
which makes processing faster and saves power.
Bitwise operators are used in C programming to perform bit-level operations i.e bit by bit.
Output
Bitwise AND(&):This operator is used to perform bit by bit ANDING between two numbers.
Lets's say num1=5,num2=7.
Binary of 5= 0 1 0 1
Binary of 7=0 1 1 1 (And)
Result: 0 1 0 1=5(in decimal)
As we have already learned about ANDING operation in Relation Operator i.e In ANDING operation multiplication is done bit by bit.
Bitwise OR(|):This operator is used to perform bit by bit ORING between two numbers.
Lets's say num1=5,num2=7.
Binary of 5= 0 1 0 1
Binary of 7=0 1 1 1 (OR)
Result: 0 1 1 1=7(in decimal)
As we have already learn about ORING operation in Relation Operator i.e In ORING operation addition is done bit by bit,but here 1+1=1 not 2 since it is binary no.
Bitwise XOR(|):This operator is similar to OR operator.The only difference between them is here 1+1=0 while in OR 1+1=1.
1 +0 =1
0 +1 =0
0 +0= 0
Lets's say num1=5,num2=7.
Binary of 5= 0 1 0 1
Binary of 7=0 1 1 1 (OR)
Result: 0 0 1 0=2(in decimal)
Bitwise Compliment or NOT(~):This operator is invert bit i.e if bit is 1 after compliment it will become 0 and if bit is 0 then it will become 1.Complimented value refers to negative value.
Let's Say num=7
Binary of 7=0 1 1 1
Result : - (1 0 0 0)=-8(in decimal)
Right Shift Operator:This operator is used to shift specified no.of bit from the right side of the number.
Let's Say num=4,num_of_bits_to_be_shifted=2;
exp=num>> num_of_bits_to_be_shifted;
Binary of 4=0 1 0 0
1 Step 0 0 1 0 -->Removed one bit from the right side and added 0 at the beginning.
2 Step 0 0 0 1 -->Removed one bit from the right side and added 0 at the beginning.
Result : 0 0 0 1
In above eg we have shifted only two bit because the value of num_of_bits_to_be_shifted was 2.
Left Shift Operator:This operator is used to shift specified no.of bit from the left side of the number.
Let's Say num=7,num_of_bits_to_be_shifted=1;
exp=num<< num_of_bits_to_be_shifted;
Binary of 7=0 1 1 1
1 Step 1 1 1 0 -->Removed one bit from the left side and added 0 at the end.
Result : 1 1 1 0
In above eg we have shifted onlyone bit because the value of num_of_bits_to_be_shifted was 1.
sizeof operator
The sizeof
is a unary operator that returns the size of data (constants, variables, array, structure, etc).
Output
friends.
Nice Explanation 😉
ReplyDeleteThanks
Delete