#include <stdio.h>
#include <stdint.h>

// 判断整数是否为2幂
/*
if (a & (a - 1))
{
    // not
}
else
{
    // yes
}
*/

uint32_t roundup_pow_of_two(const uint32_t x)
{
    if (x == 0){ return 0; }
    if (x == 1){ return 2; }
    uint32_t ret = 1;
    while (ret < x)
    {
        ret = ret << 1;
    }
    return ret;
}

int32_t main()
{
    uint32_t a = 0;
    while (scanf_s("%u",&a))
    {
        printf("%u\n", roundup_pow_of_two(a));
    }
    return 0;
}

 

相关文章:

  • 2021-12-09
  • 2022-02-02
  • 2022-12-23
  • 2022-01-08
  • 2021-06-13
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
相关资源
相似解决方案