C Programming - Bitwise Operators - Discussion

Discussion Forum : Bitwise Operators - Find Output of Program (Q.No. 11)
11.
What will be the output of the program?
#include<stdio.h>

int main()
{
    unsigned int res;
    res = (64 >>(2+1-2)) & (~(1<<2));
    printf("%d\n", res);
    return 0;
}
32
64
0
128
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
24 comments Page 2 of 3.

Karthik said:   1 decade ago
@Ranjitha

consider x>>y.
This will shift the bits of x(binary number) by y positions towards left
Ex:
1)1010>>2 = 0010
2)4>>2 (refer to exp by akash).

Ranjitha said:   1 decade ago
What >> operator will do?

Datta said:   2 decades ago
(64>>(2+1-2)) & (~(1<<2)) becomes
(64>>1) & (~(1<<2)).
In binary,
(0100 0000>>1) & (~(0000 0001<<2)
(0010 0000) & (~(0000 0100))
0010 0000 & 1111 1011 ( ~ equal to NOT )
0010 0000 = 32 (in decimal)

Akash said:   1 decade ago
>> means right shift....
It shifts d binary value by n places to right
Ex: 4>>2
0100>>2
1

Akash said:   1 decade ago
>> shifts binary value to right by n times

Ex: 4>>2
0000 0100 >> 2
0000 0001

Hence 4>>2 means 1

Swati said:   1 decade ago
What is the function of >> operator? Please explain.

Suresh said:   1 decade ago
Thank you for your explaination.

Samyukt said:   1 decade ago
Thanks yaar Datta.

Gaurav Chaudhary said:   1 decade ago
Thanks for such a nice explanation.

Santhu said:   1 decade ago
Datta is correct.


Post your comments here:

Your comments will be displayed after verification.