<?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[bool variable in einem unsigned char schreiben]]></title><description><![CDATA[<p>Hallo allerseits,</p>
<p>ich habe einen (externen) Buffer unsigned char*</p>
<pre><code>pBuffer = new unsigned char[10000];
</code></pre>
<p>und will darin an eine bestimte Stelle einen boolschen wert eintragen. Dafür habe ich eine Classe Segment erstellt die die aktuelle Bufferposition des Segments innerhalb des Buffers beinhaltet und will dort den boolschen Wert eintragen:</p>
<pre><code>class Segment{
 unsigned char* BufferPosition; // aktuelle Bufferpos

public:
 void setValue(bool);
}

inline void Segment::setValue(bool Val){
	*BufferPosition = static_cast&lt;unsigned char&gt;(Value &amp; 0x00);
}
</code></pre>
<p>es scheint so nicht zu funktionieren ich sage der inhalt der Adresse BufferPosition = 0x01 falls bVal = true</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/143724/bool-variable-in-einem-unsigned-char-schreiben</link><generator>RSS for Node</generator><lastBuildDate>Wed, 02 Sep 2026 11:30:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/143724.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 11 Apr 2006 09:46:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to bool variable in einem unsigned char schreiben on Tue, 11 Apr 2006 09:46:43 GMT]]></title><description><![CDATA[<p>Hallo allerseits,</p>
<p>ich habe einen (externen) Buffer unsigned char*</p>
<pre><code>pBuffer = new unsigned char[10000];
</code></pre>
<p>und will darin an eine bestimte Stelle einen boolschen wert eintragen. Dafür habe ich eine Classe Segment erstellt die die aktuelle Bufferposition des Segments innerhalb des Buffers beinhaltet und will dort den boolschen Wert eintragen:</p>
<pre><code>class Segment{
 unsigned char* BufferPosition; // aktuelle Bufferpos

public:
 void setValue(bool);
}

inline void Segment::setValue(bool Val){
	*BufferPosition = static_cast&lt;unsigned char&gt;(Value &amp; 0x00);
}
</code></pre>
<p>es scheint so nicht zu funktionieren ich sage der inhalt der Adresse BufferPosition = 0x01 falls bVal = true</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035024</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035024</guid><dc:creator><![CDATA[darkstar2000]]></dc:creator><pubDate>Tue, 11 Apr 2006 09:46:43 GMT</pubDate></item><item><title><![CDATA[Reply to bool variable in einem unsigned char schreiben on Tue, 11 Apr 2006 10:22:40 GMT]]></title><description><![CDATA[<p>&quot;Value &amp; 0x00&quot; ist auf jeden Fall 0 (bit-und). Lass das &amp;0x00 am besten weg, dann sollte etwas sinnvolleres rauskommen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035054</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035054</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 11 Apr 2006 10:22:40 GMT</pubDate></item><item><title><![CDATA[Reply to bool variable in einem unsigned char schreiben on Tue, 11 Apr 2006 10:40:10 GMT]]></title><description><![CDATA[<p>ja, danke erstmal. so ist es offenbar richtig, ich mache mir jedoch gedanken dass in den ersten 7 bits durchaus dann Datenmüll stehen kann, ausserdem gibt mir der compiler eine Warnung in der Ausgabefnktion:</p>
<pre><code>bool Segment::getValue(void)const{
	return static_cast&lt;bool&gt;(*BufferPosition);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1035067</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035067</guid><dc:creator><![CDATA[darkstar2000]]></dc:creator><pubDate>Tue, 11 Apr 2006 10:40:10 GMT</pubDate></item><item><title><![CDATA[Reply to bool variable in einem unsigned char schreiben on Tue, 11 Apr 2006 11:18:30 GMT]]></title><description><![CDATA[<p>Du könntest auch Bit-Operatoren verwenden, um 8 bool's in ein char zusammenzupacken:</p>
<pre><code class="language-cpp">*buffer |= 1&lt;&lt;subind;//setzen
*buffer &amp;= ~(1&lt;&lt;subind);//rücksetzen

bool val = (*buffer&amp;(1&lt;&lt;subind))!=0;//abfragen
</code></pre>
<p>(&quot;subind&quot; liegt zwischen 0 und 7 und gibt an, welches Bit du bearbeiten willst)</p>
<p>PS: oder du verwendest einen vector&lt;bool&gt;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035093</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035093</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 11 Apr 2006 11:18:30 GMT</pubDate></item><item><title><![CDATA[Reply to bool variable in einem unsigned char schreiben on Tue, 11 Apr 2006 11:18:55 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile.php?mode=viewprofile&amp;u=18038" rel="nofollow">CStoll</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=1" rel="nofollow">MFC (Visual C++)</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=15" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic.php?t=39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035094</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035094</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Tue, 11 Apr 2006 11:18:55 GMT</pubDate></item><item><title><![CDATA[Reply to bool variable in einem unsigned char schreiben on Tue, 11 Apr 2006 11:58:22 GMT]]></title><description><![CDATA[<p>oder nen bitset&lt;bool&gt;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035134</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035134</guid><dc:creator><![CDATA[Dr. Prof]]></dc:creator><pubDate>Tue, 11 Apr 2006 11:58:22 GMT</pubDate></item><item><title><![CDATA[Reply to bool variable in einem unsigned char schreiben on Tue, 11 Apr 2006 14:28:33 GMT]]></title><description><![CDATA[<p>darkstar2000 schrieb:</p>
<blockquote>
<p>ich mache mir jedoch gedanken dass in den ersten 7 bits durchaus dann Datenmüll stehen kann</p>
</blockquote>
<p>Die Sorgen sind allerdings unbegründet. bool kennt nur zwei Zustände. Dementsprechend gibt es auch nur zwei Ergebnisse bei einer Umwandlung in einen Ganzzahltyp, 0 und 1.</p>
<p>darkstar2000 schrieb:</p>
<blockquote>
<p>ausserdem gibt mir der compiler eine Warnung in der Ausgabefnktion:</p>
</blockquote>
<p>Und das wäre welche?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035299</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035299</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Tue, 11 Apr 2006 14:28:33 GMT</pubDate></item></channel></rss>