Problem with Code?? HELP

Below code is for Binary Representation of a Number.
This code works fine.....but i don't know why
if((x&(0x80000000))>0) should be <0 instead of >0
because if first bit of x is 1, number generated would be -2147483748 which is less than 0 but still this code works....
Please Help


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  #include<stdio.h>
int main()
{
    int x;
            scanf("%d",&x);
            for(int i=0;i<32;i++) 
            {
                    if((x&(0x80000000))>0)
                                       printf("1");
                    else
                        printf("0"); 
                    x=x<<1;
            }
            printf("\n");
    getchar();
    getchar();
    return 0;
}
Well x is an unsigned int.

But what is 0x80000000, signed or unsigned?

x may be cast to an unsigned int in (x&0x80000000) if 0x80000000 is an unsigned int.

Maybe a more experienced programmer can solve the riddle?

edit:

This code suggests 0x80000000 is unsigned I think.

if(0x80000000 > 0) printf("Positive\n");
Last edited on
Topic archived. No new replies allowed.