<?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[ostream hex Manipulator Problem]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich hab ein Problem beim Ausgeben eines char Arrays als hex Werte.</p>
<p>Hier ein kleines &quot;cout&quot;-Beispielprogramm:</p>
<pre><code class="language-cpp">char buffer[5];
buffer[0] = 0xa1;
buffer[1] = 0x62;
buffer[2] = 0x23;
buffer[3] = 0x84;
buffer[4] = 0xc5;

for(size_t i=0; i&lt;5; ++i)
{
   cout &lt;&lt; hex &lt;&lt; (short)buffer[i] &lt;&lt; ':';
}
</code></pre>
<p>Mein Problem:<br />
Anstatt &quot;a1:62:23:84:c5:&quot; stehen vor einigen hex Angaben &quot;ff&quot;. Sieht so aus, als würde beim casten nach short das höhere Byte hin und wieder mit 1...1 gefüllt werden.</p>
<p>Wenn ich nicht caste, bekomme ich aber nur die ASCII Darstellung der Werte. Leider gibt es keinen 1 Byte-Integer Wert.</p>
<p>Meine Frage ist also, wie ich eine gültige Ausgabe schaffe?!</p>
<p>Schonmal vielen Dank im voraus...</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/205463/ostream-hex-manipulator-problem</link><generator>RSS for Node</generator><lastBuildDate>Fri, 09 Oct 2026 03:03:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/205463.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Feb 2008 15:04:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ostream hex Manipulator Problem on Thu, 14 Feb 2008 15:04:08 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich hab ein Problem beim Ausgeben eines char Arrays als hex Werte.</p>
<p>Hier ein kleines &quot;cout&quot;-Beispielprogramm:</p>
<pre><code class="language-cpp">char buffer[5];
buffer[0] = 0xa1;
buffer[1] = 0x62;
buffer[2] = 0x23;
buffer[3] = 0x84;
buffer[4] = 0xc5;

for(size_t i=0; i&lt;5; ++i)
{
   cout &lt;&lt; hex &lt;&lt; (short)buffer[i] &lt;&lt; ':';
}
</code></pre>
<p>Mein Problem:<br />
Anstatt &quot;a1:62:23:84:c5:&quot; stehen vor einigen hex Angaben &quot;ff&quot;. Sieht so aus, als würde beim casten nach short das höhere Byte hin und wieder mit 1...1 gefüllt werden.</p>
<p>Wenn ich nicht caste, bekomme ich aber nur die ASCII Darstellung der Werte. Leider gibt es keinen 1 Byte-Integer Wert.</p>
<p>Meine Frage ist also, wie ich eine gültige Ausgabe schaffe?!</p>
<p>Schonmal vielen Dank im voraus...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1455916</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1455916</guid><dc:creator><![CDATA[Tobias W]]></dc:creator><pubDate>Thu, 14 Feb 2008 15:04:08 GMT</pubDate></item><item><title><![CDATA[Reply to ostream hex Manipulator Problem on Thu, 14 Feb 2008 15:13:22 GMT]]></title><description><![CDATA[<p>Einige Werte im Array sind grösser als 127, das bedeutet, dass sie signed sind.</p>
<pre><code class="language-cpp">unsigned char buffer[5];
buffer[0] = 0xa1;
buffer[1] = 0x62;
buffer[2] = 0x23;
buffer[3] = 0x84;
buffer[4] = 0xc5;
</code></pre>
<p>So sollte es gehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1455921</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1455921</guid><dc:creator><![CDATA[simon.gysi]]></dc:creator><pubDate>Thu, 14 Feb 2008 15:13:22 GMT</pubDate></item><item><title><![CDATA[Reply to ostream hex Manipulator Problem on Thu, 14 Feb 2008 15:50:36 GMT]]></title><description><![CDATA[<p>Klappt wunderbar, dankeschön!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1455951</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1455951</guid><dc:creator><![CDATA[Tobias W]]></dc:creator><pubDate>Thu, 14 Feb 2008 15:50:36 GMT</pubDate></item><item><title><![CDATA[Reply to ostream hex Manipulator Problem on Thu, 14 Feb 2008 18:05:02 GMT]]></title><description><![CDATA[<p>Es geht auch ohne Änderung des Buffertyps.</p>
<pre><code class="language-cpp">cout &lt;&lt; hex; // einmal reicht
for(size_t i=0; i&lt;5; ++i)
{
   cout &lt;&lt; int( static_cast&lt; unsigned char &gt;( buffer[i] ) ) &lt;&lt; ':';
}
</code></pre>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1456042</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1456042</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Thu, 14 Feb 2008 18:05:02 GMT</pubDate></item><item><title><![CDATA[Reply to ostream hex Manipulator Problem on Thu, 14 Feb 2008 19:27:08 GMT]]></title><description><![CDATA[<p>Werner Salomon schrieb:</p>
<blockquote>
<p>Es geht auch ohne Änderung des Buffertyps.</p>
<pre><code class="language-cpp">cout &lt;&lt; hex; // einmal reicht
for(size_t i=0; i&lt;5; ++i)
{
   cout &lt;&lt; int( static_cast&lt; unsigned char &gt;( buffer[i] ) ) &lt;&lt; ':';
}
</code></pre>
<p>Gruß<br />
Werner</p>
</blockquote>
<p>Liefert das auch die gewünschte Ausgabe wenn char == unsigned char ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1456097</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1456097</guid><dc:creator><![CDATA[Frager]]></dc:creator><pubDate>Thu, 14 Feb 2008 19:27:08 GMT</pubDate></item><item><title><![CDATA[Reply to ostream hex Manipulator Problem on Thu, 14 Feb 2008 19:33:43 GMT]]></title><description><![CDATA[<p>Frager schrieb:</p>
<blockquote>
<p>Liefert das auch die gewünschte Ausgabe wenn char == unsigned char ist?</p>
</blockquote>
<p>char ist immer ein anderer Typ als unsigned char ... oder wie darf ich die Frage verstehen? Auch wenn die Typen gleich wären, wäre das Ergebnis das gleiche, aber dann hätte Tobias das Problem gar nicht gehabt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1456108</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1456108</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Thu, 14 Feb 2008 19:33:43 GMT</pubDate></item><item><title><![CDATA[Reply to ostream hex Manipulator Problem on Thu, 14 Feb 2008 19:40:45 GMT]]></title><description><![CDATA[<p>No na.</p>
<p>greetz, Swordfish</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1456118</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1456118</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Thu, 14 Feb 2008 19:40:45 GMT</pubDate></item><item><title><![CDATA[Reply to ostream hex Manipulator Problem on Fri, 15 Feb 2008 07:29:18 GMT]]></title><description><![CDATA[<p>Werner Salomon schrieb:</p>
<blockquote>
<p>char ist immer ein anderer Typ als unsigned char ... oder wie darf ich die Frage verstehen?</p>
</blockquote>
<p>Es ist nicht definiert, ob char vorzeichenbehaftet ist. Der Wertebereich kann also über 127 hinausgehen, muss aber nicht (altes C-Erbe, deshalb gibts überhaupt die 3 Typen).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1456287</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1456287</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Fri, 15 Feb 2008 07:29:18 GMT</pubDate></item><item><title><![CDATA[Reply to ostream hex Manipulator Problem on Fri, 15 Feb 2008 13:37:53 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>Werner Salomon schrieb:</p>
<blockquote>
<p>char ist immer ein anderer Typ als unsigned char ... oder wie darf ich die Frage verstehen?</p>
</blockquote>
<p>Es ist nicht definiert, ob char vorzeichenbehaftet ist. Der Wertebereich kann also über 127 hinausgehen, muss aber nicht (altes C-Erbe, deshalb gibts überhaupt die 3 Typen).</p>
</blockquote>
<p>Ich bin mir ganz sicher, dass Werne das weiß. Seine Aussage bleibt auch unabhängig davon richtig. Es spielt keine Rolle ob char signed oder unsigned ist, char ist *garantiert* ein eigenständiger Typ und damit niemals gleich unsigned char. Und wenn es um die Werte geht, die char im Falle signed vs. unsigned repräsentieren kann: Werners Lösung funktioniert selbstverständlich in beiden Fällen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1456513</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1456513</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Fri, 15 Feb 2008 13:37:53 GMT</pubDate></item><item><title><![CDATA[Reply to ostream hex Manipulator Problem on Fri, 15 Feb 2008 15:20:16 GMT]]></title><description><![CDATA[<p>Jop. So steht es im Standard geschrieben: Es gibt die Datentypen char, signed char und unsigned char. Als was char nun gesetzt ist, steht nicht fest(s. Hummes Antwort).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1456583</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1456583</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Fri, 15 Feb 2008 15:20:16 GMT</pubDate></item></channel></rss>