<?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[2 chars zu short]]></title><description><![CDATA[<p>Hallo,<br />
ich möchte 2 chars zu einem short konvertieren. Mein momentaner Code sieht so aus:</p>
<pre><code class="language-cpp">unsigned high = 42;
unsigned char low = 23;
unsigned short both = static_cast&lt;unsigned short&gt;(high &lt;&lt; 8 | low);
std::cout &lt;&lt; both &lt;&lt; std::endl;
// Ausgabe 10775
</code></pre>
<p>Nun funktioniert diese Code nur mit Little-Endian Maschinen. Auf wikiepdia steht jetzt, dass heutige PC Systeme alle Little-Endian benutzen, stimmt das, und wenn nicht, was für eine Plattformübergreifende Methode gibt es?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/287212/2-chars-zu-short</link><generator>RSS for Node</generator><lastBuildDate>Thu, 20 Aug 2026 14:40:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/287212.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 24 May 2011 18:34:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 2 chars zu short on Tue, 24 May 2011 18:34:44 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich möchte 2 chars zu einem short konvertieren. Mein momentaner Code sieht so aus:</p>
<pre><code class="language-cpp">unsigned high = 42;
unsigned char low = 23;
unsigned short both = static_cast&lt;unsigned short&gt;(high &lt;&lt; 8 | low);
std::cout &lt;&lt; both &lt;&lt; std::endl;
// Ausgabe 10775
</code></pre>
<p>Nun funktioniert diese Code nur mit Little-Endian Maschinen. Auf wikiepdia steht jetzt, dass heutige PC Systeme alle Little-Endian benutzen, stimmt das, und wenn nicht, was für eine Plattformübergreifende Methode gibt es?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2068078</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2068078</guid><dc:creator><![CDATA[Charakter]]></dc:creator><pubDate>Tue, 24 May 2011 18:34:44 GMT</pubDate></item><item><title><![CDATA[Reply to 2 chars zu short on Tue, 24 May 2011 18:42:52 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">static_cast&lt;unsigned short&gt;((high &lt;&lt; 8) + low);
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>edit: Und ob alle heutigen PC-Systeme LittelEndian benutzen kommt auf deine genaue Definition von PC und heutig an. Man kann jedenfalls schon sagen, dass es nicht unrealistisch ist, mal einem BigEndian System zu begegnen und man sich nicht einschränken sollte. Besonders wenn es so einfach ist wie hier!</p>
<p>edit: Ups, Operator + hat Vorrang vor &lt;&lt;. Klammern gesetzt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2068082</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2068082</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 24 May 2011 18:42:52 GMT</pubDate></item><item><title><![CDATA[Reply to 2 chars zu short on Tue, 24 May 2011 18:38:47 GMT]]></title><description><![CDATA[<p>Idee: Du könntest die Funktion htons nutzen. Diese sollte auf allen POSIX-System vorhanden sein und konvertiert die Eingabe in die sogenannte Network-Order (Big-Endian).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2068083</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2068083</guid><dc:creator><![CDATA[hkjhk]]></dc:creator><pubDate>Tue, 24 May 2011 18:38:47 GMT</pubDate></item><item><title><![CDATA[Reply to 2 chars zu short on Tue, 24 May 2011 18:51:25 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/19375">@SeppJ</a>:<br />
Aber wenn ich jetzt doch ein Big-Endian System habe dann sieht high als short ja so aus:</p>
<pre><code>00101010 00000000
</code></pre>
<p>Wenn ich das jetzt nach links shifte kommt doch 0 raus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2068094</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2068094</guid><dc:creator><![CDATA[Charakter]]></dc:creator><pubDate>Tue, 24 May 2011 18:51:25 GMT</pubDate></item><item><title><![CDATA[Reply to 2 chars zu short on Tue, 24 May 2011 18:52:49 GMT]]></title><description><![CDATA[<p>Charakter schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/19375">@SeppJ</a>:<br />
Aber wenn ich jetzt doch ein Big-Endian System habe dann sieht high als short ja so aus:</p>
<pre><code>00101010 00000000
</code></pre>
<p>Wenn ich das jetzt nach links shifte kommt doch 0 raus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
</blockquote>
<p>Nein. Die Shiftoperatoren arbeiten unabhängig von der internen Darstellung. Das sind mathematische Operatoren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2068097</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2068097</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 24 May 2011 18:52:49 GMT</pubDate></item><item><title><![CDATA[Reply to 2 chars zu short on Tue, 24 May 2011 18:57:32 GMT]]></title><description><![CDATA[<p>Das bedeutet also, dass ein Shiftoperator nach links bei Big-Endian Systemen zu einem Shiftoperator nach rechts mutiert, oder wie soll ich das verstehen? Denn Little-Endian ist ja die Darstellung, wie wir sie im Alltag benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2068102</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2068102</guid><dc:creator><![CDATA[Charakter]]></dc:creator><pubDate>Tue, 24 May 2011 18:57:32 GMT</pubDate></item><item><title><![CDATA[Reply to 2 chars zu short on Tue, 24 May 2011 19:01:53 GMT]]></title><description><![CDATA[<p>Charakter schrieb:</p>
<blockquote>
<p>Das bedeutet also, dass ein Shiftoperator nach links bei Big-Endian Systemen zu einem Shiftoperator nach rechts mutiert, oder wie soll ich das verstehen? Denn Little-Endian ist ja die Darstellung, wie wir sie im Alltag benutzen.</p>
</blockquote>
<p>Nein. Die interne Darstellung interessiert den Shiftoperator überhaupt gar nicht. Da kann auch ein kleiner Kobold mit Zettel und Stift im Rechner sitzen, es kommt trotzdem das gleiche dabei raus. Oder der Rechner rechnet intern mit dreiwertigen Bits. Oder Quantenbits. Alles egal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2068106</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2068106</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 24 May 2011 19:01:53 GMT</pubDate></item><item><title><![CDATA[Reply to 2 chars zu short on Tue, 24 May 2011 19:23:15 GMT]]></title><description><![CDATA[<p>Charakter schrieb:</p>
<blockquote>
<p>Denn Little-Endian ist ja die Darstellung, wie wir sie im Alltag benutzen.</p>
</blockquote>
<p>Im Allrag wie in der Mathematik benutzt man Big-Endian.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2068120</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2068120</guid><dc:creator><![CDATA[ipsec]]></dc:creator><pubDate>Tue, 24 May 2011 19:23:15 GMT</pubDate></item><item><title><![CDATA[Reply to 2 chars zu short on Wed, 25 May 2011 04:54:58 GMT]]></title><description><![CDATA[<p>ipsec schrieb:</p>
<blockquote>
<p>Im Allrag wie in der Mathematik benutzt man Big-Endian.</p>
</blockquote>
<pre><code>1               1                11
Eintausend  Einhundert  Elf
</code></pre>
<p>Wo sind denn da die großen Zahlem am Ende?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2068208</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2068208</guid><dc:creator><![CDATA[Charakter]]></dc:creator><pubDate>Wed, 25 May 2011 04:54:58 GMT</pubDate></item><item><title><![CDATA[Reply to 2 chars zu short on Wed, 25 May 2011 05:52:15 GMT]]></title><description><![CDATA[<p>Also zumindest bei meinem Zahlenverständnis ist immer noch Eintausend &gt; Einhundert &gt; Elf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2068214</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2068214</guid><dc:creator><![CDATA[ipsec]]></dc:creator><pubDate>Wed, 25 May 2011 05:52:15 GMT</pubDate></item><item><title><![CDATA[Reply to 2 chars zu short on Wed, 25 May 2011 08:23:42 GMT]]></title><description><![CDATA[<p>Charakter schrieb:</p>
<blockquote>
<p>Hallo,<br />
ich möchte 2 chars zu einem short konvertieren. Mein momentaner Code sieht so aus:</p>
<pre><code class="language-cpp">unsigned high = 42;
unsigned char low = 23;
unsigned short both = static_cast&lt;unsigned short&gt;(high &lt;&lt; 8 | low);
std::cout &lt;&lt; both &lt;&lt; std::endl;
// Ausgabe 10775
</code></pre>
<p>Nun funktioniert diese Code nur mit Little-Endian Maschinen. Auf wikiepdia steht jetzt, dass heutige PC Systeme alle Little-Endian benutzen, stimmt das, und wenn nicht, was für eine Plattformübergreifende Methode gibt es?</p>
</blockquote>
<p>Sofern ein unsigned char auf der jeweiligen Plattform tatsächlich einem Oktett entspricht, ist es egal, ob Little- oder Big-Endian. Dann wird das so funktionieren.</p>
<p>Und es ist nicht alles Little-Endian. Die JVM arbeitet z.B. mit Big-Endian. Zumindest nach außen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2068263</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2068263</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Wed, 25 May 2011 08:23:42 GMT</pubDate></item><item><title><![CDATA[Reply to 2 chars zu short on Wed, 25 May 2011 12:02:39 GMT]]></title><description><![CDATA[<p>Charakter schrieb:</p>
<blockquote>
<p>ipsec schrieb:</p>
<blockquote>
<p>Im Allrag wie in der Mathematik benutzt man Big-Endian.</p>
</blockquote>
<pre><code>1               1                11
Eintausend  Einhundert  Elf
</code></pre>
<p>Wo sind denn da die großen Zahlem am Ende?</p>
</blockquote>
<p>Sie stehen am linken Ende. Und das Ende ists, um das es geht:</p>
<p>wikipedia schrieb:</p>
<blockquote>
<p>Bei Big-Endian [...] wird das Byte mit den höchstwertigen Bits (d. h. die signifikantesten Stellen) zuerst gespeichert, das heißt an der kleinsten Speicheradresse.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2068402</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2068402</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Wed, 25 May 2011 12:02:39 GMT</pubDate></item></channel></rss>