How to shift >= 32 bits in uint64_t?

回眸只為那壹抹淺笑 提交于 2019-12-01 22:31:11

How to shift >= 32 bits in uint64_t?

If your compiler supports long long:

boost::uint64_t x = 1LL << 32;

Otherwise:

boost::uint64_t x = boost::uint64_t(1) << 32;

Shouldn't it be fine since the type has 64 bits?

No. Even though x is 64 bits, 1 isn't. 1 is 32 bits. How you use a result has no effect on how that result is generated.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!