C Programming - Bitwise Operators - Discussion
Discussion Forum : Bitwise Operators - Find Output of Program (Q.No. 2)
2.
If an unsigned int is 2 bytes wide then, What will be the output of the program ?
#include<stdio.h>
int main()
{
unsigned int m = 32;
printf("%x\n", ~m);
return 0;
}
Discussion:
35 comments Page 4 of 4.
Divya said:
1 decade ago
Thanks for your explanation.
Sudheer kumar raina said:
1 decade ago
1) 32--> in binary--> for 2 bytes --> 0000 0000 0010 0000.
2) Now ~m makes all 0's to 1's and viceversa. ---> 1111 1111 1101 1111.
3) Now lets convert them into hexa, as %x is specified as format specifier.
4) Now the output in 2nd step becomes "f (15) f (d (13) f" in hexa decimal.
5) Finally "ffdf" is the answer.
2) Now ~m makes all 0's to 1's and viceversa. ---> 1111 1111 1101 1111.
3) Now lets convert them into hexa, as %x is specified as format specifier.
4) Now the output in 2nd step becomes "f (15) f (d (13) f" in hexa decimal.
5) Finally "ffdf" is the answer.
Raja said:
1 decade ago
~m= ones compliment of m.
Replace binary form of 32 with its compliment form.
Replace 0 with 1 and 1 with 0.
Replace binary form of 32 with its compliment form.
Replace 0 with 1 and 1 with 0.
Neetu said:
1 decade ago
32 can be written as 0000 0000 0010 0000 in 2 bytes and complement operator convert this to
1111 1111 1101 1111
1111 1111 1101 1111
Kishore said:
1 decade ago
Bcoz purpose of ~ will act as NOT operator and hence in binary equivalent as shows as 1111 1111 1101 1111.... hence option c..
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers