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;
}
Discussion:
42 comments Page 4 of 5.
NITESH said:
1 decade ago
Ok so -1 is being treated here as 256. Thanx Atul.
Vineet said:
1 decade ago
Hello,
Why are you all taking -1 as 8 bit number? I can't understand because by default every integer constant is of 16 bits.
Why are you all taking -1 as 8 bit number? I can't understand because by default every integer constant is of 16 bits.
Sangharsh said:
2 decades ago
How is 32 << -1 is equal to 0 ?
Kumar said:
1 decade ago
How can 1111 1111 be 256, its 255 no? if I am wrong please tell me how it is?
Kumar said:
1 decade ago
32<<-1 is similar to -1>>32.Try this you will get answer 0 for that
Kasi said:
1 decade ago
I need bief explanation of >>, << for these two operartors with an example.
Can any one help me.
Can any one help me.
Ravishankara Asakapalli said:
1 decade ago
I need a complete Explanation on the 0xfffff. i didn't get what exactly it means.............
Kgp vinod said:
1 decade ago
Ravishankara Asakapalli :
0xfffff this is hexadecimal number.
where f=1111
so ffff=1111 1111 1111 1111
0xfffff this is hexadecimal number.
where f=1111
so ffff=1111 1111 1111 1111
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.
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.
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers