强转基本数据类型

1
2
3
4
5
6
7
8
9
10
11
12
13
union A{
int a;
char b[4];
}a;
a.a=1;
if (a.b[0] == 0)
{

NSLog(@"big");
} else {
//小端
NSLog(@"little");
}

result

1
2015-08-05 11:53:40.497 UITest[1856:82057] little

结论: ios是小端模式(低地址放低位)


1
2
3
4
5
long long l = 0x1234567887654321;
int i = l >>32 & 0xffffffff;
int j = (int)l;
int16_t t = (int16_t)l;
NSLog(@"l = %llx i = %x j = %x t = %x" , l ,i ,j , t);

reslut

1
2015-08-05 11:46:35.040 UITest[1786:78739] l = 1234567887654321 i = 12345678 j = 87654321 t = 4321

结论: 强转是截取低位的