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;
}
ffff
0000
ffdf
ddfd
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
35 comments Page 2 of 4.

Sanjay said:   1 decade ago
Good explain munni.

Chinnu said:   1 decade ago
Thanks munni thanku so much.

Jayakrishana said:   1 decade ago
Thanks for you explanation Sudheer Kumar Raina.

Jagajjeevan said:   1 decade ago
~a=-(a+1)
~32=-(32+1)=-33

Binary of 33 : 0000 0000 0001 0001
1's of 33 : 1111 1111 1110 1110
2's of 33(-33): 1
1111 1111 1110 1111
f f d f
~32 is ffdf

Vignesh said:   1 decade ago
What does "f"&"d" mean and any thing others.

Chelsi said:   1 decade ago
How did you took m=32 as in binary: 0000 0000 0010 0000 please explain me?

Naveen said:   1 decade ago
But in the compiler provided by the indiabix.com.

The output is ffffffdf.

Can anyone explain why?

Raina said:   1 decade ago
HOW TO WRITE .

32 = 0000 0000 0010 0000.

Can anyone explain this?

Sravanthi said:   1 decade ago
Assume each digit from right to left as 2 power i.
Where i =0,1,2...

Now 32 is 0000 0000 0010 0000.

Which mean 0*(2 power 0)+0*(2 power 1)+0*(2 power 2)+0*(2 power 3)+0*(2 power 4)+1*(2 power 5)+0*(2 power 6)+..

Gaurav bisht said:   1 decade ago
Since unsigned 2 byte m = 32 can be represented as:

0000 0000 0010 0000

To do ~m means just complimenting m i.e.

~m = 1111 1111 1101 1111

In Hexa 1111 = f and 1101 = d

Therefore result is ffdf.


Post your comments here:

Your comments will be displayed after verification.