Boost C++ Libraries: Ticket #12627: export_bits() gives wrong answer on fixed precision type https://svn.boost.org/trac10/ticket/12627 <p> The following minimal working example prints the wrong answer. Compiled on Ubuntu 16.04, and the console prints: </p> <pre class="wiki">➜ ~ clang++ -std=c++14 bug.cpp ➜ ~ ./a.out FEDCBA9876543210F1E2D3C4B5A69788 f1e2d3c4b5a69788f1e2d3c4b5a69788 ➜ ~ </pre><p> I think those numbers should be the same, and they are different. It behaves like the low order 64 bits got serialized twice, and the high order 64 bits never got serialized at all. </p> <p> If you change the number type from uint128_t to cpp_int, then the example runs fine which is why I think this problem occurs only with fixed precision types. </p> <pre class="wiki">#include &lt;boost/multiprecision/cpp_int.hpp&gt; #include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;cstdint&gt; namespace mp = boost::multiprecision; int main() { mp::uint128_t i = mp::uint128_t(0xFEDCBA9876543210) &lt;&lt; 64 | 0xF1E2D3C4B5A69788; std::cout &lt;&lt; std::hex &lt;&lt; i &lt;&lt; std::endl; std::vector&lt;std::uint8_t&gt; v(16); export_bits(i, v.begin(), 8); std::for_each(v.begin(), v.end(), [](std::uint8_t byte) { std::cout &lt;&lt; (int)byte; }); std::cout &lt;&lt; std::endl; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12627 Trac 1.4.3 John Maddock Fri, 02 Dec 2016 17:58:51 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/12627#comment:1 https://svn.boost.org/trac10/ticket/12627#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Confirmed: it's specific to 128-bit and less types that use <span class="underline">int128 internally. </span></p> <p> Fixed in <a class="ext-link" href="https://github.com/boostorg/multiprecision/commit/fe3eac52bfb050e3751edb045e6dd4fa52645bd8"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/fe3eac52bfb050e3751edb045e6dd4fa52645bd8</a> </p> Ticket