Bitwise operators in Arithmetic
instruction in c
Hello friends,
Today I am
going to tell you what is bitwise operators in Arithmetic instruction in c? and how
it performs its function in Arithmetic instruction in c programming language.
In this post i will tell you how many types of bitwise operators in c
programming and its function also.
In previous
post we will discuss about what is athematic instruction in very detail so,
please see previous post to reach the previous post please click on athematic instruction in c programming it
appears green. If you do not read the previous post then you can not able to
understand what is going on in this post and you leave this website so, please
read my previous post.
Now let’s
start todays topic which is bitwise operators
also read
(Fundamental-terminologies-part-2)
What are bitwise operators
Bitwise
operator is used to manipulate BIT level data. This operator is used for
shifting from right to left and left to right bit. The bitwise operator does
not apply to float and double data types.
Computer
only works on 0 and 1. The full form of Bit is a binary digit which is 0 and 1.
The bitwise operator is calculated at 0 and 1. Whenever we manipulate the
decimal number by bitwise operator, the processor first converts it to the form
of 0 and 1 and then calculates it.
Now if you
understand what is bitwise operators then now let’s know type of bitwise
operators
How many types of bitwise operators
in Arithmetic instruction in c?
Basically,
there are six type of bitwise operators which are given below
Description |
operators
|
Bitwise - And |
& |
Bitwise - Or |
| |
Bitwise - Xor |
^ |
Bitwise - Not |
~ |
Right - shift |
>> |
left - shift |
<< |
Now we study
type of bitwise operators in very detail so let’s start with first type of
bitwise operators
Behavior of & operator
0 & 0 = 0
0 & 1 = 0
1 & 0 = 0
1 & 1 = 1
If one operand is 0 and second operand is also 0 then the result is also 0.
If one
operand is 0 and second operand is 1 then the result is also 0.
If one
operand is 1 and second operand is also 0 then the result is also 0.
If one
operand is 1 and second operand is also 1 then the result is also 1.
If you
understand the behavior of & operators then now let’s take an example for
better understanding of function of & operators in athematic instruction in c programming
Example:1
Int x;
X = 23 & 56;
Now we first
convert this number into binary number then we solve this according to &
behavior
23 = 10111
56 = 111000
We have to
wright this in 16 bits because integer constant consumes 16 bits so we use 0 to
make this number 16 bit
23 = 0000
0000 0001 0111
56 = 0000
0000 0011 1000
Now we can
perform & operators
23 = 0000
0000 0001 0111
56 = 0000 0000 0011 1000
16 = 0000
0000 0001 0000
The output
screen shows 16 answer
Behavior of “Or” operator
0 | 0 = 0
0 | 1 = 1
1 | 0 = 1
1 | 1 = 1
If one
operand is 0 and second operand is also 0 then the result is also 0.
If one
operand is 0 and second operand is 1 then the result is 1.
If one
operand is 1 and second operand is also 0 then the result is also 1.
If one
operand is 1 and second operand is also 1 then the result is also 1
If you
understand the behavior of ‘|’ operators then now let’s take an example for
better understanding of function of ‘|’ operators in athematic instruction in c programming
Example:2
Int x;
X = 23 | 56;
23 = 0000
0000 0001 0111
56 = 0000 0000 0011 1000
63 = 0000
0000 0011 1111
The output
screen shows 63 answer
Behavior of “^” operator
0 ^ 0 = 0
1 ^ 0 = 1
0 ^ 1 = 1
1 ^ 1 = 0
‘Xor’ says
if both numbers are same then the result is 0 and if both numbers are not same
then the result is 1
If you
understand the behavior of ‘^’ operators then now let’s take an example for
better understanding of function of ‘^’ operators in athematic instruction in c programming
Example:3
Int x;
X = 23 | 56;
23 = 0000
0000 0001 0111
56 = 0000 0000 0011 1000
47 = 0000
0000 0010 1111
The output
screen shows 47 answer
Now let’s know
about the function of right shift operator
Function of right shift operator
In this
operator, we shift the binary number into right side by using 0.
Take an
example for better understanding
Example:4
Int x;
X = 56 >> 2;
56 = 0000
0000 0011 1000
We add left
side = 00
The number
will be
14 = 0000 0000 0000 1110
We right 2
so we shift 56 right side by using two 0. If we write any number at the place
of 2 for example, we wright 4 then we add four 0 from the left side.
Hope you
understand
For this we
add two 0 in left side and through this, the number shift right side
Hence, the
output screen shows 14 answer.
Function of left shift operator
In this
operator, we shift the binary number into left side by using 0.
Take an
example for better understanding
Example:5
Int x;
X = 56 << 3;
56 = 0000
0000 0011 1000
We add right
side = 000
The number
will be
448 = 0000
0001 1100 0000
We right 3
so we shift 56 right side by using three 0. If we write any number at the place
of 3 for example, we wright 4 then we add four 0 from the right side.
Hope you
understand
For this we
add three 0 in right side and through this, the number shift left side
Hence, the
output screen shows 448 answer.
Hope you
understand the bitwise operators. If you have any quarry about bitwise operator
then you can comment me on comment box.
Thanks for
reading this post
Also read
1 Comments
for any quarry please comment me here
ReplyDeletePlease do not enter any spam link in the comment box and please follo me.