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.
Preeti said:
1 decade ago
Binary representation of 32bit - 0000000000100000.
1's - 1111111111011111.
So ffdf answer.
1's - 1111111111011111.
So ffdf answer.
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.
Shruti said:
1 decade ago
How 32 is 0000 0000 0010 0000 ?
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?
Mounika kursing said:
1 decade ago
32 16 8 4 2 1
2^5 2^4 2^3 2^2 2^1 2^0
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1
f f d f
We want 32, So keep 1 at 32 all other 0.
For negation replace 0's with 1's.
2^5 2^4 2^3 2^2 2^1 2^0
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1
f f d f
We want 32, So keep 1 at 32 all other 0.
For negation replace 0's with 1's.
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.
Meghana k said:
2 years ago
Thank you it was helpful.
Mallesh said:
3 months ago
#include<stdio.h>
int main()
{
unsigned int m = 32;
printf("%x\n", ~m);
return 0;
}
Ans:-
1's complement: Inverting the bits ( all 1s to 0s and all 0s to 1s).
Binary of 32(2 byte) : 0000 0000 0010 0000.
Representing -32: Make it 1's complement then,
1s complement of 32(2byte) : 1111 1111 1101 1111.
This is the result: ffdf
int main()
{
unsigned int m = 32;
printf("%x\n", ~m);
return 0;
}
Ans:-
1's complement: Inverting the bits ( all 1s to 0s and all 0s to 1s).
Binary of 32(2 byte) : 0000 0000 0010 0000.
Representing -32: Make it 1's complement then,
1s complement of 32(2byte) : 1111 1111 1101 1111.
This is the result: ffdf
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
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
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
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers