Other Operators

8. Other Operators
Bitwise Operators
Bitwise operators are
Shift left
<< 
Shift right
>> 
Exclusive Or
^
Bitwise And
&
Bitwise Or
|

Shift Left (<<):- Shift left means multiplied by 2. Before the << we have a number. That number is multiplied by 2. After the << we have another number that tells how many no.of times before << number is multiplied by 2.

<< operator example.




output







Shift Right (>>):- Shift right means divided by 2. Before the >> we have a number. That number is divided by 2. After the >> we have another number  that tells how many no. of times before >> number  is divided by 2.

>> operator example.










output











Exclusive or (^):- Exclusive or converts the given numbers into binary form according to the truth table it produce the result. If both the number1 value and number2 value are same the result is 0 else 1. After calculating the exclusive or it converts into the number form.
number1
number2
result
1
1
0
1
0
1
0
1
1
0
0
0

^ operator example.

























output












Bitwise And (&):- Before and after the bitwise and operator values convert into the binary form according to the bitwise and truth it produce binary form result. Then we have to convert the binary form result to number form. If number1 and number2 binary form values are 1(true) the result is true(1).
number1
number2
result
1
1
1
1
0
0
0
1
0
0
0
0

& operator example 














output














Bitwise Or (|):- Before and after the bitwise or operator values convert into the binary form according to the bitwise or truth table it produce binary form result. Then we have to convert the binary form result to number form. If number1 and number2 binary form values are 0(false) the result is false(0).
number1
number2
result
1
1
0
1
0
1
0
1
1
0
0
1

| operator example.














output



Tilde operator(~):- The tilde(~) is an operator is a unary operator that takes the expression to its right performs this small algorithm on it (where N is the expression to the right of the tilde): -(N+1).

~ operator example.
/* ~ operator example */
#include<stdio.h>
main()
{
int n;
clrscr();
printf("Enter a Number");
scanf("%d",&n);
printf("~(%d) =%d",n,~n);
getch();
}

Sizeof Operator:- Sizeof operator is used to know the size of datatypes. i.e. either integer or character or floating point decimal or double.
Syntax:- sizeof(<datatype>);
Syntax:-sizeof(<variablename>);
It shows the size of the variable bytes i.e int means 2, char means 1 etc.

Knowing sizes program.











output












& operator is used to assign the address to the variable.
* operator is used to hold the address and value it is used generally before the variable name.

. Operator is known as member access operator in structures for accessing the structure variables with in the main().

To know the ranges of datatypes program

output

No comments:

Post a Comment