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 1 of 4.

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..

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

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.

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.

Divya said:   1 decade ago
Thanks for your explanation.

Abani said:   1 decade ago
Binary representation of 32 in 16bit(turbo c) is 0000000000100000

Hence 1's complement of 32 is 1111111111011111 and whose hexadecimal form is FFDF which is option C.

Munni said:   1 decade ago
m=32
In binary: 0000 0000 0010 0000
Hence ~m : 1111 1111 1101 1111
f f d f

Hence C is answer.

NEERAJ KUMAR said:   1 decade ago
Thank nitu

Shilpa said:   1 decade ago
Thanks Neetu & Sudheer Kumar Raina, very well explianed.

Sudhir kushwaha said:   1 decade ago
m=32
In binary: 0000 0000 0010 0000
~ it called tiled i.e. 1's complement of given no.
Hence ~m : 1111 1111 1101 1111

f f d f

Hence C is answer


Post your comments here:

Your comments will be displayed after verification.