我想了解整數提升如何與算術移位運算符一起工作。特別是,我想知道,a, b, c, d, e, f, g, h
的哪些值是根據C++ 14標準精確定義的,哪些可以取決於平臺/硬件/編譯器(假設爲sizeof(int) == 4
)。布爾型左移和右移
int a = true << 3;
int b = true >> 3;
int c = true << 3U;
int d = true >> 3U;
int e = true << 31;
int f = true >> 31;
int g = true << 31U;
int h = true >> 31U;
可能的重複:[使用位運算符爲布爾](http://stackoverflow.com/questions/24542/using-bitwise-operators-for-booleans-in-c) –
@ThomasMatthews你鏈接的問題不說話關於偏移。 – Winter