C Programming - Bitwise Operators - Discussion

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

int main()
{
    printf("%d %d\n", 32<<1, 32<<0);
    printf("%d %d\n", 32<<-1, 32<<-0);
    printf("%d %d\n", 32>>1, 32>>0);
    printf("%d %d\n", 32>>-1, 32>>-0);
    return 0;
}
Garbage values
64 32
0 32
16 32
0 32
All zeros
8 0
0 0
32 0
0 16
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
42 comments Page 3 of 5.

Ravishankara Asakapalli said:   1 decade ago
I need a complete Explanation on the 0xfffff. i didn't get what exactly it means.............

Saikumar said:   1 decade ago
Compiler dependent question on gcc 4.7.2 the answer is:

64 32
16 32
16 32
64 32

Kumar said:   1 decade ago
32<<-1 is similar to -1>>32.Try this you will get answer 0 for that

Ankush said:   1 decade ago
Please explain the answer as per GCC compiler. It is:
64 32
16 32
16 32
64 32

Kumar said:   1 decade ago
How can 1111 1111 be 256, its 255 no? if I am wrong please tell me how it is?

Udit said:   6 years ago
Please explain the following in the code.
1. 32>>-0
2. 32<<-0

Sai said:   8 years ago
Can any one tell me when we are taking 16 bit number & 8 bit number?

Rashmi mate said:   1 decade ago
How is 32 << -1 is equal to 0 ? I'm unable to understand this.

Animesh said:   7 years ago
I got an output 32 <<-1 = 64 and 32>>-1=16;

Am I right?

Himani said:   9 years ago
Please, explain 32>>-1 and 32<<-1 in easy way.


Post your comments here:

Your comments will be displayed after verification.