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 2 of 4.
Sangita said:
1 decade ago
The output is ffffffdf. in indiabix.com because its runs on 32 bit linux environment. If we run in turbo it will give ffff.
It varies from platform to platform.
It varies from platform to platform.
Anirudh sharma said:
9 years ago
~ 32 = (32 + 1) *-1.
- 33
33 = 0000 0000 0010 0001.
2complemnt is:
1111 1111 1101 1111
f f d f
So the answer is f f d f.
- 33
33 = 0000 0000 0010 0001.
2complemnt is:
1111 1111 1101 1111
f f d f
So the answer is f f d f.
(7)
Sravanthi said:
1 decade ago
I don't understand the above procedure can anyone lease explain me in brief I mean how to write the values of 32 in binary form?
Munni said:
1 decade ago
m=32
Hence C is answer.
In binary: 0000 0000 0010 0000
Hence ~m : 1111 1111 1101 1111
f f d f
Hence C is answer.
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..
Shreya said:
10 years ago
32 = 2^5 = 2*2*2*2*2. So here 2^5 bit is 1 = 0000 0000 0010 0000.
But what they have asked is ~m so = 1111 1111 1101 1111.
But what they have asked is ~m so = 1111 1111 1101 1111.
S.Loguprasad said:
1 decade ago
~ act like Not. 32 in binary 0000 0000 0010 0000. Convert to Not So 1111 1111 1101 1111. Answer in hexadecimal ffdf.
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
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.
Selvameenal C said:
8 years ago
Yes, there is m=32=0000 0000 0010 0000;
~m(1s complement)= 1111 1111 1101 1111;
Thus answer : ffdf.
~m(1s complement)= 1111 1111 1101 1111;
Thus answer : ffdf.
(3)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers