# binary

Discussion in 'C' started by gpk kishore, Jul 29, 2011.

1. ### gpk kishoreNew Member

Joined:
Jun 30, 2011
Messages:
82
0
Trophy Points:
0
#include<stdio.h>
#include<conio.h>
void main()
{
unsigned int m=32;
printf("%x",~m);
}
sir

it's urgent for me

why?

2. ### eriyerNew Member

Joined:
Jan 22, 2011
Messages:
32
0
Trophy Points:
0
What is the question / doubt with regard to this program where you are displaying the value in hex after inverting the bits ?

3. ### gpk kishoreNew Member

Joined:
Jun 30, 2011
Messages:
82
0
Trophy Points:
0
sir
printf("%x",~m);
it will print (~m) value in hexa decimal system

please explain me the output with explanation

4. ### srp5789New Member

Joined:
Jul 25, 2011
Messages:
6
0
Trophy Points:
0
output will be ==> ffdf
its just complement of 0000 0000 0010 0000 or (0020 in hex or 32 in int/unsigned)
i.e 1111 1111 1101 1111 (ffdf in hex or 65503 in unsigned or -33 in int)

5. ### gpk kishoreNew Member

Joined:
Jun 30, 2011
Messages:
82
0
Trophy Points:
0
thank u sir
but i think
when we are taking complement we invert all the bits but we will not invert sign bit
is it crct or not

6. ### srp5789New Member

Joined:
Jul 25, 2011
Messages:
6
0
Trophy Points:
0
in C 2's complement method is used to represent numbers because of that when you say -1 its not
1000 0000 0000 0001 but
1111 1111 1111 1111

procedure to get this is

1.write magnitude of original number in binary format i.e. 1 instead of -1

0000 0000 0000 0001

2.now invert the bits i.e. (~number)

1111 1111 1111 1110

3.now add 1 to step 2

1111 1111 1111 1111

here the representation of -1, which is FFFF(1111 1111 1111 1111) and not 8001 (1000 0000 0000 0001).