C++ 位移位时是否有n位的限制?
在尝试为bitboard类提出方案时,我决定使用全局编译时变量来表示关键的bitboard配置,例如所有black Rook的初始位置C++ 位移位时是否有n位的限制?,c++,bit-manipulation,bitwise-operators,constexpr,C++,Bit Manipulation,Bitwise Operators,Constexpr,在尝试为bitboard类提出方案时,我决定使用全局编译时变量来表示关键的bitboard配置,例如所有black Rook的初始位置 constexpr uint64_t BLACK_ROOK_INIT = 0x1 | (0x1 << 56); constexpr uint64\t BLACK\u ROOK\u INIT=0x1(0x1这是您想要的: #include <iostream> int main(){ constexpr uint64_t BLAC
constexpr uint64_t BLACK_ROOK_INIT = 0x1 | (0x1 << 56);
constexpr uint64\t BLACK\u ROOK\u INIT=0x1(0x1这是您想要的:
#include <iostream>
int main(){
constexpr uint64_t BLACK_ROOK_INIT = 0x1ULL | (0x1ULL << 56);
std::cout<<BLACK_ROOK_INIT<<std::endl;
}
这就是你想要的:
#include <iostream>
int main(){
constexpr uint64_t BLACK_ROOK_INIT = 0x1ULL | (0x1ULL << 56);
std::cout<<BLACK_ROOK_INIT<<std::endl;
}
1
是一个int
。您可以使用uint64_t(1)
来获取更大的值。这仍然无法编译。我将在上面附加说明。1是int。转换为int64_t发生在移位之后。您需要1LL。您应该先强制转换,然后再移位,(int64_t(1)1
是一个int
。您可以使用uint64_t(1)
来获取更大的值。这仍然无法编译。我将在上面附加说明。1是int。转换为int64_t发生在移位之后。您需要1LL。您应该先强制转换,然后再移位,(int64_t(1)
#include <iostream>
int main(){
constexpr uint64_t BLACK_ROOK_INIT = 0x1ULL | (0x1ULL << 56);
std::cout<<BLACK_ROOK_INIT<<std::endl;
}
#include <iostream>
int main(){
constexpr uint64_t BLACK_ROOK_INIT = (uint64_t)(0x1) | ((uint64_t)(0x1) << 56);
std::cout<<BLACK_ROOK_INIT<<std::endl;
}