Converting unsigned number and the number of symbols have

Ado, direct work!

 

  Casts of the substance (common data type):

    1, to maintain the same bit value, just change the way explain the position of (the highest level is interpreted as the sign bit, etc.)

    2, the short or short type data into unsigned type, the data is first converted to an int type, int type and then converted to an unsigned int.

 

E.g:

unsigned short   c = 12345;

short                  a = -12345;

unsigned short   b = a;

 

c complement: 1,001,110,000,001,100

a complement: 1,001,110,000,001,100

b complement: 1,001,110,000,001,100

 

Print the value 53191 b.

They exist in the form of visible memory is the same, but the interpretation is different.

 

Unsigned number and a signed number to compare:

int a = -1; unsigned int b = 1;           ------->  a > b

char a = -1; unsigned char b = 1;    ------->  a < b

int a = -1; unsigned charb = -1;           ------->  a < b

char a = -1; unsigned int b = -1;    ------->  a = b

 

in conclusion:

    Unsigned int type encountered, is converted into an unsigned int compared, are converted to type int otherwise compare data

 

Guess you like

Origin www.cnblogs.com/hujingzheng/p/11613769.html