I am currently working on a project where I need to use uint8_t. I found one problem, can someone explain to me why this is happening?
//using DIGIT_T = std::uint8_t; using DIGIT_T = std::uint32_t; std::uint8_t bits = 1; DIGIT_T test1 = ~(DIGIT_T)0; std::cout << std::hex << (std::uint64_t)test1 << std::endl; DIGIT_T test2 = ((~(DIGIT_T)0) >> bits); std::cout << std::hex << (std::uint64_t)test2 << std::endl;
in this case, the output will be as expected
ffffffff 7fffffff
but when i uncomment the first line and i use uint8_t, the output will be
ff ff
This behavior is causing me problems.
Thank you for your help.
Marek
source share