如何将一个无符号整数转为向上最接近该数的2的整数次方值
RT
例如: 3转成4; 11转成16; 222转成256;
谢谢各位了.
[解决办法]
- C/C++ code
#include <stdio.h>int main(){ unsigned int x; printf("Please input a number :"); scanf("%d", &x); unsigned int mask = 0x10000000; while (mask) { if (mask & x) { if (mask != x) { mask <<= 1; } printf("The result is %u\n", mask); return 0; } mask >>= 1; }}
[解决办法]
1楼程序mask = 0x10000000应该是 0x80000000
[解决办法]