Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 位移位时是否有n位的限制?_C++_Bit Manipulation_Bitwise Operators_Constexpr - Fatal编程技术网

C++ 位移位时是否有n位的限制?

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

在尝试为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 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;
}