<?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[Aufgabe mit union - Verbund]]></title><description><![CDATA[<p>So hier mal eine Aufgabe an der ich ne ganze Weile gessen habe und zu keinen vernünftigen Ergebnis gekommen bin. Vielleicht kommt ihr ja drauf was man in die Kommentarzeilen setzten muss. Hier die ganze Aufgabe:</p>
<blockquote>
<p>Bei einer 16 Bit großen Speicherzelle umfasst das Low Byte die obersten Bits von 0 bis 7 und das High Byte die Bits 8 bis 15.</p>
<p>Untersuchen Sie das nachfolgende Programmfragment um ergänzen Sie es um die Definition aller erforderlichen benutzerdefinierten Typen:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

// ...

int main() {
    if (sizeof(unsigned short int) != 2) {
        cout &lt;&lt; &quot;Unpassende Groesse von \&quot;unsigned short int\&quot; ungleich 2\n&quot;
             &lt;&lt; &quot;Programm abgebrochen.&quot;
             &lt;&lt; endl;
             return 1;
    }
    Umwandlung u;
    cout &lt;&lt; &quot;unsigned short int-Wert: &quot;;
    cin &gt;&gt; u.ganzzahl;
    cout &lt;&lt; &quot;High Byte: &quot;
         &lt;&lt; u.bytes.highByte - 0
         &lt;&lt; &quot;\nLow Byte: &quot;
         &lt;&lt; u.bytes.lowByte + 0
         &lt;&lt; endl;
    return 0;
}
</code></pre>
<p>Wenn Sie das korrekt vervollständigte Programm übersetzen und ausführen, gibt es das High Byte und das Low Byte eines einzugebenden unsigned short int-Wertes aus, zum Beispiel:<br />
unsigned short int-Wert: 32799<br />
Low Byte: 31<br />
High Byte: 128</p>
<p>Senden Sie das vollständige Quellprogramm als Lösung ein.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/topic/133083/aufgabe-mit-union-verbund</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 18:48:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/133083.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 15 Jan 2006 12:18:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Aufgabe mit union - Verbund on Sun, 15 Jan 2006 12:18:15 GMT]]></title><description><![CDATA[<p>So hier mal eine Aufgabe an der ich ne ganze Weile gessen habe und zu keinen vernünftigen Ergebnis gekommen bin. Vielleicht kommt ihr ja drauf was man in die Kommentarzeilen setzten muss. Hier die ganze Aufgabe:</p>
<blockquote>
<p>Bei einer 16 Bit großen Speicherzelle umfasst das Low Byte die obersten Bits von 0 bis 7 und das High Byte die Bits 8 bis 15.</p>
<p>Untersuchen Sie das nachfolgende Programmfragment um ergänzen Sie es um die Definition aller erforderlichen benutzerdefinierten Typen:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

// ...

int main() {
    if (sizeof(unsigned short int) != 2) {
        cout &lt;&lt; &quot;Unpassende Groesse von \&quot;unsigned short int\&quot; ungleich 2\n&quot;
             &lt;&lt; &quot;Programm abgebrochen.&quot;
             &lt;&lt; endl;
             return 1;
    }
    Umwandlung u;
    cout &lt;&lt; &quot;unsigned short int-Wert: &quot;;
    cin &gt;&gt; u.ganzzahl;
    cout &lt;&lt; &quot;High Byte: &quot;
         &lt;&lt; u.bytes.highByte - 0
         &lt;&lt; &quot;\nLow Byte: &quot;
         &lt;&lt; u.bytes.lowByte + 0
         &lt;&lt; endl;
    return 0;
}
</code></pre>
<p>Wenn Sie das korrekt vervollständigte Programm übersetzen und ausführen, gibt es das High Byte und das Low Byte eines einzugebenden unsigned short int-Wertes aus, zum Beispiel:<br />
unsigned short int-Wert: 32799<br />
Low Byte: 31<br />
High Byte: 128</p>
<p>Senden Sie das vollständige Quellprogramm als Lösung ein.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/966977</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/966977</guid><dc:creator><![CDATA[P*trick]]></dc:creator><pubDate>Sun, 15 Jan 2006 12:18:15 GMT</pubDate></item><item><title><![CDATA[Reply to Aufgabe mit union - Verbund on Sun, 15 Jan 2006 12:54:08 GMT]]></title><description><![CDATA[<p>Ich weiß nicht genau wie sich der Aufgaben Steller das vorstellt, aber ich würde es so lösen:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

class Umwandlung
{
    private:
        unsigned char data[2];
    public:
        Umwandlung(unsigned short int was)
        {
            data[0] = *(reinterpret_cast&lt;unsigned char*&gt;(&amp;was));
            data[1] = *(reinterpret_cast&lt;unsigned char*&gt;(&amp;was) + 1);
        }
        unsigned char HighByte()
        {
            return data[0];
        }
        unsigned char LowByte()
        {
            return data[1];
        }
};

int main() {
    if (sizeof(unsigned short int) != 2) {
        cout &lt;&lt; &quot;Unpassende Groesse von \&quot;unsigned short int\&quot; ungleich 2\n&quot;
             &lt;&lt; &quot;Programm abgebrochen.&quot;
             &lt;&lt; endl;
             return 1;
    }
    Umwandlung *u;
    cout &lt;&lt; &quot;unsigned short int-Wert: &quot;;
    unsigned short int t;
    cin &gt;&gt; t;
    u = new Umwandlung(t);
    cout &lt;&lt; &quot;High Byte: &quot;
         &lt;&lt; static_cast&lt;int&gt;(u-&gt;HighByte())
         &lt;&lt; &quot;\nLow Byte: &quot;
         &lt;&lt; static_cast&lt;int&gt;(u-&gt;LowByte())
         &lt;&lt; endl;
    delete u;
    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/967005</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/967005</guid><dc:creator><![CDATA[joomoo]]></dc:creator><pubDate>Sun, 15 Jan 2006 12:54:08 GMT</pubDate></item><item><title><![CDATA[Reply to Aufgabe mit union - Verbund on Sun, 15 Jan 2006 13:07:18 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">union Umwandlung 
{
    unsigned short ganzzahl;
    struct {
        char highByte;
        char lowByte;
    } bytes;   
};
</code></pre>
<p>Sowas ist wohl gefragt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/967016</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/967016</guid><dc:creator><![CDATA[FireFlow]]></dc:creator><pubDate>Sun, 15 Jan 2006 13:07:18 GMT</pubDate></item><item><title><![CDATA[Reply to Aufgabe mit union - Verbund on Sun, 15 Jan 2006 13:24:49 GMT]]></title><description><![CDATA[<p>Knapp daneben <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<pre><code class="language-cpp">union Umwandlung
{
   unsigned short ganzzahl;
   struct {
      unsigned char lowByte;
      unsigned char highByte;
   }bytes;  
};
</code></pre>
<p>Kurt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/967028</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/967028</guid><dc:creator><![CDATA[ZuK]]></dc:creator><pubDate>Sun, 15 Jan 2006 13:24:49 GMT</pubDate></item><item><title><![CDATA[Reply to Aufgabe mit union - Verbund on Sun, 15 Jan 2006 13:29:18 GMT]]></title><description><![CDATA[<p>Danke erstmal für die schnelle Antwort. Jetzt geht es! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/967029</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/967029</guid><dc:creator><![CDATA[P*trick]]></dc:creator><pubDate>Sun, 15 Jan 2006 13:29:18 GMT</pubDate></item><item><title><![CDATA[Reply to Aufgabe mit union - Verbund on Sun, 15 Jan 2006 13:28:53 GMT]]></title><description><![CDATA[<p>Die struct brauchst du nicht.<br />
FireFlow's Lösung war fast richtig. Siehe mein voriges Posting<br />
Kurt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/967032</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/967032</guid><dc:creator><![CDATA[ZuK]]></dc:creator><pubDate>Sun, 15 Jan 2006 13:28:53 GMT</pubDate></item></channel></rss>