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.

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

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

64 32
16 32
16 32
64 32

Sindhu said:   1 decade ago
32<<1 means : Binary value of 32 is 00100000 << 1 gives 01000000 gives 64.

32<<0 has no change gives the same value.

32<<-1 means: As -1 is negative number should take its 2's compliment value i.e 15 .so << by 15bits gives result zero to binary value of 32.

Vasani Anil said:   1 decade ago
printf("%d %d\n", 32<<1, 32<<0); // 64 32 same as operation.

printf("%d %d\n", 32<<-1, 32<<-0);

-1=11111111 11111111 it's value more than 16 so o/p 0 32.

printf("%d %d\n", 32>>1, 32>>0);

printf("%d %d\n", 32>>-1, 32>>-0);// same as above reason.

Shikha said:   1 decade ago
For an instance 32<<1
32 can be written as : 0011 0010
When you shift left by 1 bit, you get : 0110 0100
Which is 64. Similarly you can try for all options.

Kgp vinod said:   1 decade ago
Ravishankara Asakapalli :
0xfffff this is hexadecimal number.
where f=1111
so ffff=1111 1111 1111 1111

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

Kasi said:   1 decade ago
I need bief explanation of >>, << for these two operartors with an example.
Can any one help me.

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

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


Post your comments here:

Your comments will be displayed after verification.