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 2 of 5.

Sairam said:   9 years ago
int main()
{
int a = 10, b = 5, c = 5;
int d;
d = b + c == a;
printf(&quot;%d&quot;, d);
}

Can anyone say answer for this?

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

Siva said:   1 decade ago
Tell me the value of 60 and ~60 same how? explain now.

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

Jason said:   8 years ago
The behavior is undefined according to "standard" C. You may interpret -1 as shift into opposite direction ( << -1 is actually >> 1) or you may interpret as (unsigned ) -1.

Ankita said:   7 years ago
How to convert -0 to its 2's complement?

Laxman said:   7 years ago
-1 times shifting is exactly equal to 31 times according to gcc when given variable is intiger type.

Md Wasim Akram said:   7 years ago
In Codeblock GCC Compiler 32 Bit its o/p is;

64 32
16 32
16 32
64 32

But unfortunately, this answer is not available in option.

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

Am I right?

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


Post your comments here:

Your comments will be displayed after verification.