unsigned int is 4 bytes in the system i'm programming. i printed sizeof(unsigned int) and it said 4.

int main(int argc, char * argv[])
{
        unsigned int a = 0;
        long int b = 2607503366;
/* the b data type must strictly be a long int */ 
        a = (unsigned int) b;
        printf("%d\n",a);
        return 0;
}

it prints out;

-1687463930

but it must print the same thing. what am i doing wrong?

thanks.

Because you used a signed type, and your unsigned value is outside the permitted range of your machine.

You also used the wrong printf format, try %lu instead.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.