copyMSB - set all bits of result to most significant bit of x.
Examples: copyMSB(0x80000000) = 0xFFFFFFFF copyMSB(0x70000000) = 0x00000000 Legal ops: ! ~ & ^ | + << >> Max ops: 5
不能用if-else。
copyMSB - set all bits of result to most significant bit of x.
Examples: copyMSB(0x80000000) = 0xFFFFFFFF copyMSB(0x70000000) = 0x00000000 Legal ops: ! ~ & ^ | + << >> Max ops: 5
不能用if-else。
unsigned int copyMSB(unsigned int x)
{
return x >> 31 << 31;
}
int main()
{
printf("%d\n", copyMSB(0x80000000));
printf("%d\n", copyMSB(0x70000000));
}