Upcoming SlideShare
×

# Lecture 11 bitwise_operator

977 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
977
On SlideShare
0
From Embeds
0
Number of Embeds
289
Actions
Shares
0
49
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Lecture 11 bitwise_operator

1. 1. www.eshikshak.co.in
2. 2. ● An operator used for manipulation of data at bit level ● It is used for testing bits, shifting them right or left ● It works on integer and character data type ● It is not applied to float or doublewww.eshikshak.co.in
3. 3. Operator Meaning~ One’s compliment>> Shift right<< Shift left& Bitwise AND| Bitwise OR^ Bitwise exclusive OR www.eshikshak.co.in
4. 4. ● All the 1’s present in the number are changed to 0’s and all 0’s are changed to 1’s ● Example 1’s complement of 1101 = 0010 1’s complement of 1010 = 0101www.eshikshak.co.in
5. 5. main(){int j,k;j=12;k=~j;printf(“One’s complement of %d is”,j);showbits(k);}ExampleOne’s complement of 12 is 0011www.eshikshak.co.in
6. 6. ● It is represent by >> ● It shifts each bit in operand to the right ● Example ch >> 1 This will shift all bits in ch one place to the rightch >> 5This will shift all bits in ch five places to the rightwww.eshikshak.co.in
7. 7. main(){int j,k,i;i=12;for(j=0;j<4;j++){k = i >> j;printf(“%d right shift %d gives”,i,j);showbits(k);}}Output12 right shift 0 gives 110012 right shift 1 gives 011012 right shift 2 gives 001112 right shift 3 gives 0001www.eshikshak.co.in
8. 8. ● It is represent by << ● It shifts each bit in operand to the left ● Example ch << 1 This will shift all bits in ch one place to the leftch << 5This will shift all bits in ch five places to the leftwww.eshikshak.co.in
9. 9. main(){int j,k,i;i= 3;for(j=0;j<4;j++){k = i << j;printf(“%d right shift %d gives”,i,j);showbits(k);}}Output12 right shift 0 gives 001112 right shift 1 gives 000112 right shift 2 gives 000012 right shift 3 gives 0000www.eshikshak.co.in
10. 10. ● & operator operates on two operands● This operator will compared two operands on bit-by-bit basis● Both the operands must be of same type (either char or int)● & and && are different operator, && is logical AND operator whereas & is Bitwise AND operator 1st Bit 2nd Bit 1st & 2nd Bit 0 0 0 0 1 0 1 0 0 1 1 1 www.eshikshak.co.in
11. 11. ● The uses of bitwise AND operator a) It is used whether a particular bit in a number is ON or OFFb) It is used to turn OFF a particular bit in a number www.eshikshak.co.in
12. 12. www.eshikshak.co.in