View Single Post
  #4   Spotlight this post!  
Unread 05-01-2008, 22:42
Foster Foster is offline
Engineering Program Management
VRC #8081 (STEMRobotics)
Team Role: Mentor
 
Join Date: Jul 2007
Rookie Year: 2005
Location: Delaware
Posts: 1,392
Foster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond reputeFoster has a reputation beyond repute
Re: Signed and unsigned variables

int main(int argc, char *argv[])
{
unsigned int u;
int i;

u = 0; // i should be -32768.
i = (unsigned int) u;
printf("%d %u\n",i , u);
i = (unsigned int) (u - 32768);
printf("%d %u\n",i , u);

u = 32768; // i should be 0.
i = (unsigned int) u;
printf("%d %u\n",i , u);
i = (unsigned int) (u - 32768);
printf("%d %u\n",i , u);

u=65535; // i should be 32767.
i = (unsigned int) u;
printf("%d %u\n",i , u);
i = (unsigned int) (u - 32768);
printf("%d %u\n",i , u);
return 0;
}

0 0
-32768 0

32768 32768
0 32768

65535 65535
32767 65535

Your test case with output. Did that help?