uint8_t VS uint32_t different behaviour <p>I am currently working on project where I need to use uint8_t. I have found one problem, could someone explain to me why this happens ?</p> <pre><code>//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 &lt;&lt; std::hex &lt;&lt; (std::uint64_t)test1 &lt;&lt; std::endl; DIGIT_T test2 = ((~(DIGIT_T)0) &gt;&gt; bits); std::cout &lt;&lt; std::hex &lt;&lt; (std::uint64_t)test2 &lt;&lt; std::endl; </code></pre> <p>in this case the output is as expected</p> <pre><code>ffffffff 7fffffff </code></pre> <p>but when I uncomment the first line and I use uint8_t the output is</p> <pre><code>ff ff </code></pre> <p>This behaviour is causing me troubles.</p> <p>Thank you for your help.</p> <p>Marek</p>