short s =7;// Big Endian: => 00000000 00000111// Little Endian: => 00000111 00000000float f =-7.0;// Big Endian: => 11000000 11100000 00000000 00000000// Little Endian: => 00000000 00000000 11100000 11000000
原始数据类型之间的转化
char 转 short
char ch ='A';short s = ch;// Big Endian:// ch: => 01000000// s: => 00000000 01000001// Little Endian:// ch: => 01000001// s: => 01000001 00000000
short 转 int
short s =1033;int i = s;// Big Endian:// s: => 00000100 00001001// i: => 00000000 00000000 00000100 00001001// Little Endian:// s: => 00001001 00000100// i: => 00001001 00000100 00000000 00000000short s =-1;int i = s;// Big Endian: (符号位延续)// s: => 11111111 11111111// i: => 11111111 11111111 11111111 11111111// Little Endian:// s: => 11111111 11111111// i: => 11111111 11111111 11111111 11111111
int 转 short
int i =10502151;short s = i;// Big Endian:// s: => 01000000 00000111// i: => 00000000 10100000 01000000 00000111// Little Endian:// s: => 00000111 01000000// i: => 00000111 01000000 10100000 00000000int i =-65536;short s = i;// Big Endian:// s: => 00000000 00000000// i: => 11111111 11111111 00000000 00000000// Little Endian:// s: => 00000000 00000000// i: => 00000000 00000000 11111111 11111111
int 转 float
int i =5;float f = i;// 神奇地转化,非截断,而是保持原数值大小,这也是方便平时计算需求// f: => 01000001 00100000 00000000 00000000// i: => 00000000 00000000 00000000 00000101