<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[boost - byte order]]></title><description><![CDATA[<p>hallo leute,<br />
kleine frage bzgl boost::dynamic_bitset:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;boost/dynamic_bitset.hpp&gt;

template &lt; typename T &gt;
inline T highbit(T&amp; t)
{
   return t = (((T)(-1)) &gt;&gt; 1) + 1;
}

template &lt; typename T &gt;
std::ostream&amp; bin(T&amp; value, std::ostream &amp;o)
{
   for ( T bit = highbit(bit); bit; bit &gt;&gt;= 1 )
   {
  	o &lt;&lt; ( ( value &amp; bit ) ? '1' : '0' );
   }
   return o;
}

int main(int, char*[]) 
{
  unsigned int value = 0x701;
  boost::dynamic_bitset&lt;unsigned char&gt; x(16, value); // all 0's by default
  unsigned char y[2];
  memset(&amp;y, 0, sizeof(y));
  std::cout &lt;&lt; &quot;x[i]: &quot;;
  for (boost::dynamic_bitset&lt;&gt;::size_type i = 0; i &lt; x.size(); ++i)
    std::cout &lt;&lt; x[i];
  std::cout &lt;&lt; &quot;\n&quot;;
  std::cout &lt;&lt; &quot;x: &quot; &lt;&lt; x &lt;&lt; &quot;\n&quot;;
  std::cout &lt;&lt; &quot;x.num_blocks(): &quot; &lt;&lt; x.num_blocks() &lt;&lt; std::endl; 

  to_block_range(x, y);
  for(unsigned int i = 0; i &lt; 2; i++)
  {
     bin(y[i], std::cout);
     std::cout &lt;&lt; std::endl;
  }
  std::cout &lt;&lt; &quot;\n&quot;;
  return EXIT_SUCCESS;
}
</code></pre>
<p>wenn ich das char array anschaue steht dann da (binaer):<br />
y[0] = 00000001<br />
y[1] = 00000111</p>
<p>ich möchte da gerne die byte ordner schon im boost::dynamic_bitset aendern, wie kann ich auf den block zugreifen?<br />
soll dann im char array folgend aussehen:<br />
y[0] = 00000111<br />
y[1] = 00000001<br />
[/cpp]</p>
<p>bye</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/226686/boost-byte-order</link><generator>RSS for Node</generator><lastBuildDate>Wed, 30 Sep 2026 18:59:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/226686.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 04 Nov 2008 16:46:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to boost - byte order on Tue, 04 Nov 2008 16:46:16 GMT]]></title><description><![CDATA[<p>hallo leute,<br />
kleine frage bzgl boost::dynamic_bitset:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;boost/dynamic_bitset.hpp&gt;

template &lt; typename T &gt;
inline T highbit(T&amp; t)
{
   return t = (((T)(-1)) &gt;&gt; 1) + 1;
}

template &lt; typename T &gt;
std::ostream&amp; bin(T&amp; value, std::ostream &amp;o)
{
   for ( T bit = highbit(bit); bit; bit &gt;&gt;= 1 )
   {
  	o &lt;&lt; ( ( value &amp; bit ) ? '1' : '0' );
   }
   return o;
}

int main(int, char*[]) 
{
  unsigned int value = 0x701;
  boost::dynamic_bitset&lt;unsigned char&gt; x(16, value); // all 0's by default
  unsigned char y[2];
  memset(&amp;y, 0, sizeof(y));
  std::cout &lt;&lt; &quot;x[i]: &quot;;
  for (boost::dynamic_bitset&lt;&gt;::size_type i = 0; i &lt; x.size(); ++i)
    std::cout &lt;&lt; x[i];
  std::cout &lt;&lt; &quot;\n&quot;;
  std::cout &lt;&lt; &quot;x: &quot; &lt;&lt; x &lt;&lt; &quot;\n&quot;;
  std::cout &lt;&lt; &quot;x.num_blocks(): &quot; &lt;&lt; x.num_blocks() &lt;&lt; std::endl; 

  to_block_range(x, y);
  for(unsigned int i = 0; i &lt; 2; i++)
  {
     bin(y[i], std::cout);
     std::cout &lt;&lt; std::endl;
  }
  std::cout &lt;&lt; &quot;\n&quot;;
  return EXIT_SUCCESS;
}
</code></pre>
<p>wenn ich das char array anschaue steht dann da (binaer):<br />
y[0] = 00000001<br />
y[1] = 00000111</p>
<p>ich möchte da gerne die byte ordner schon im boost::dynamic_bitset aendern, wie kann ich auf den block zugreifen?<br />
soll dann im char array folgend aussehen:<br />
y[0] = 00000111<br />
y[1] = 00000001<br />
[/cpp]</p>
<p>bye</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1610152</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1610152</guid><dc:creator><![CDATA[cpp1]]></dc:creator><pubDate>Tue, 04 Nov 2008 16:46:16 GMT</pubDate></item></channel></rss>