1
//若val為0則返回0, val為負數則返回-1, 為正數返回1
2
int32_t check32(int32_t val)
3
{
4
int32_t a = val >> 31;
5
int32_t b = (val & 0x0000FFFF) | ((val >> 16)&0x0000FFFF);
6
b = (b & 0x000000FF) | ((b >> 8)&0x000000FF);
7
b = (b & 0x0000000F) | ((b >> 4)&0x0000000F);
8
b = (b & 0x00000003) | ((b >> 2)&0x00000003);
9
b = (b & 0x00000001) | ((b >> 1)&0x00000001);
10
return a|b;
11
}
12
13
//若val為0則返回0, 否則返回1
14
uint32_t check32(uint32_t val)
15
{
16
uint32_t a = (val & 0x0000FFFF) | ((val >> 16)&0x0000FFFF);
17
a = (a & 0x000000FF) | ((a >> 8)&0x000000FF);
18
a = (a & 0x0000000F) | ((a >> 4)&0x0000000F);
19
a = (a & 0x00000003) | ((a >> 2)&0x00000003);
20
a = (a & 0x00000001) | ((a >> 1)&0x00000001);
21
return a;
22
}
//若val為0則返回0, val為負數則返回-1, 為正數返回12
int32_t check32(int32_t val)3
{4
int32_t a = val >> 31;5
int32_t b = (val & 0x0000FFFF) | ((val >> 16)&0x0000FFFF);6
b = (b & 0x000000FF) | ((b >> 8)&0x000000FF);7
b = (b & 0x0000000F) | ((b >> 4)&0x0000000F);8
b = (b & 0x00000003) | ((b >> 2)&0x00000003);9
b = (b & 0x00000001) | ((b >> 1)&0x00000001);10
return a|b;11
}12

13
//若val為0則返回0, 否則返回114
uint32_t check32(uint32_t val)15
{16
uint32_t a = (val & 0x0000FFFF) | ((val >> 16)&0x0000FFFF);17
a = (a & 0x000000FF) | ((a >> 8)&0x000000FF);18
a = (a & 0x0000000F) | ((a >> 4)&0x0000000F);19
a = (a & 0x00000003) | ((a >> 2)&0x00000003);20
a = (a & 0x00000001) | ((a >> 1)&0x00000001);21
return a;22
}



