| Issue |
176636
|
| Summary |
Unexpected bit shift operation results ( a bug? )
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
VisionShilin
|
Result of the bit shift operation like "(01011111 << 4) >> 4" should be "00001111" instead of "01011111".
The following codes showed an unexpected result while std::bitset works fine.
//main.cpp
#include <iostream>
#include <cstdint>
#include <bitset>
int main()
{
uint8_t i = 0x5F;
std::bitset<8> bs(i);
std::cout << "(0x5F >> 4) << 4 ==> " << std::bitset<8>((i >> 4) << 4) << std::endl;
std::cout << "(0x5F << 4) >> 4 ==> " << std::bitset<8>((i << 4) >> 4) << " (instead of 00001111 !!!)" << std::endl;
std::cout << "(bitset(01011111) << 4) >> 4 ==> " << ((bs << 4) >> 4) << std::endl;
std::cout << "uint8_t(0x5F << 4) >> 4 ==> " << std::bitset<8>(uint8_t(i << 4) >> 4) << std::endl;
}
Running results:
(0x5F >> 4) << 4 ==> 01010000
(0x5F << 4) >> 4 ==> 01011111 (instead of 00001111 !!!)
(bitset(01011111) << 4) >> 4 ==> 00001111
uint8_t(0x5F << 4) >> 4 ==> 00001111
compile command:
clang++ main.cpp -o t
or
g++ main.cpp -o t
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs