<?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[aus zwei Bytes ein Zahl einlesen]]></title><description><![CDATA[<p>Hallo Leute,<br />
ich habe in einem Char charWert[0] = 7 und in char Wert [1] = 79<br />
so die beiden Zahlen sind Hexadecimal und ich würde gerne das ergebnis für<br />
Hexadecimal 779 ausrechen und es in einem neuen variablen speichern<br />
also int intWert;<br />
also 779 ist decimal 1913 ich würde gerne in meinem intWert =1913 haben</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/252876/aus-zwei-bytes-ein-zahl-einlesen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 03:19:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/252876.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 25 Oct 2009 21:07:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to aus zwei Bytes ein Zahl einlesen on Sun, 25 Oct 2009 21:07:34 GMT]]></title><description><![CDATA[<p>Hallo Leute,<br />
ich habe in einem Char charWert[0] = 7 und in char Wert [1] = 79<br />
so die beiden Zahlen sind Hexadecimal und ich würde gerne das ergebnis für<br />
Hexadecimal 779 ausrechen und es in einem neuen variablen speichern<br />
also int intWert;<br />
also 779 ist decimal 1913 ich würde gerne in meinem intWert =1913 haben</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798264</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798264</guid><dc:creator><![CDATA[borhan]]></dc:creator><pubDate>Sun, 25 Oct 2009 21:07:34 GMT</pubDate></item><item><title><![CDATA[Reply to aus zwei Bytes ein Zahl einlesen on Sun, 25 Oct 2009 21:21:39 GMT]]></title><description><![CDATA[<p>Probier mal mit ::memcpy(). Weiß allerdings nicht ob der int die Zeichen als hexadezimal anerkennt. Ansonsten vorher von Hex zu ASCII konvertieren. <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/1798269</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798269</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Sun, 25 Oct 2009 21:21:39 GMT</pubDate></item><item><title><![CDATA[Reply to aus zwei Bytes ein Zahl einlesen on Sun, 25 Oct 2009 21:23:05 GMT]]></title><description><![CDATA[<p>Das Prinzip des Stellenverschiebens ist im Hexadezimalsystem auch nicht anders als im Dezimalsystem. Um eine Stelle nach rechts zu verschieben, musst du mit 16 multiplizieren, bei zwei Stellen mit 16²...<br />
Um die Anzahl der Stellen von Wert[1] herauszubekommen, kannst du den Logarithmus verwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798270</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798270</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Sun, 25 Oct 2009 21:23:05 GMT</pubDate></item><item><title><![CDATA[Reply to aus zwei Bytes ein Zahl einlesen on Sun, 25 Oct 2009 21:43:30 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int intWert = (charWert[0] &lt;&lt; 8) | charWert[1];
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1798282</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798282</guid><dc:creator><![CDATA[Registrierter Troll]]></dc:creator><pubDate>Sun, 25 Oct 2009 21:43:30 GMT</pubDate></item><item><title><![CDATA[Reply to aus zwei Bytes ein Zahl einlesen on Sun, 25 Oct 2009 22:37:09 GMT]]></title><description><![CDATA[<p>danke,<br />
intWert= (charWert[0]&lt;&lt;8)|charWert[1];<br />
das funktioniert mein probelm ist aber das ich in charWert [1] = -70 stehen habe es sollte aber BA stehen. Kannst du mir vielleicht auch sagen wie ich dieses Problem umgehe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798293</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798293</guid><dc:creator><![CDATA[borhan]]></dc:creator><pubDate>Sun, 25 Oct 2009 22:37:09 GMT</pubDate></item><item><title><![CDATA[Reply to aus zwei Bytes ein Zahl einlesen on Mon, 26 Oct 2009 05:49:39 GMT]]></title><description><![CDATA[<p>Hexadezimal ist nichts anderes als eine interpretatiton. Wenn du es dir als Hex anzeigen läst kommt da schon BA raus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798334</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798334</guid><dc:creator><![CDATA[Xebov]]></dc:creator><pubDate>Mon, 26 Oct 2009 05:49:39 GMT</pubDate></item><item><title><![CDATA[Reply to aus zwei Bytes ein Zahl einlesen on Mon, 26 Oct 2009 10:36:05 GMT]]></title><description><![CDATA[<p>borhan schrieb:</p>
<blockquote>
<p>Hallo Leute,<br />
ich habe in einem Char charWert[0] = 7 und in char Wert [1] = 79<br />
so die beiden Zahlen sind Hexadecimal</p>
</blockquote>
<p>&quot;hexadezimal&quot; ist keine Eigenschaft einer Zahl wie &quot;gerade&quot; und &quot;ungerade&quot;. Das Hexadezimalsystem ist eine Art der <em>Darstellung</em> von Zahlen.</p>
<p>borhan schrieb:</p>
<blockquote>
<p>Registrierter Troll schrieb:</p>
<blockquote>
<pre><code class="language-cpp">int intWert = (charWert[0] &lt;&lt; 8) | charWert[1];
</code></pre>
</blockquote>
<p>danke,<br />
intWert= (charWert[0]&lt;&lt;8)|charWert[1];<br />
das funktioniert mein probelm ist aber das ich in charWert [1] = -70 stehen habe es sollte aber BA stehen. Kannst du mir vielleicht auch sagen wie ich dieses Problem umgehe</p>
</blockquote>
<p>Diese Bitfrickelei auf vorzeichenbehafteten Zahlen sollte man meist sein lassen. Man muss auch daran denken, dass man nie direkt mit char- und short-Typen rechnet, sondern dass immer eine Konvertierung zu int oder unsigned int stattfindet (&quot;promotion&quot;).</p>
<p>Soll das Ergebnis denn eine vorzeichenlose Zahl im Bereich [0,65536) sein? <a href="http://www.cplusplus.com/reference/clibrary/climits/" rel="nofollow">INT_MAX</a> kann nämlich auch kleiner als 65535 sein.</p>
<p>Versuch das hier:</p>
<pre><code class="language-cpp">unsigned char const* p = reinterpret_cast&lt;unsigned char const*&gt;(charWert);
unsigned int intWert = (unsigned(p[0]) &lt;&lt; 8) | p[1];
</code></pre>
<p>(unter der Annahme, dass charWert ein Array oder ein Zeiger ist)</p>
<p>Ein</p>
<pre><code class="language-cpp">#include &lt;climits&gt;
#if CHAR_BIT !=8
#error &quot;CHAR_BIT != 8&quot;
#endif
</code></pre>
<p>könnte auch nützlich sein.</p>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798433</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798433</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Mon, 26 Oct 2009 10:36:05 GMT</pubDate></item><item><title><![CDATA[Reply to aus zwei Bytes ein Zahl einlesen on Mon, 26 Oct 2009 19:10:15 GMT]]></title><description><![CDATA[<p>es funktioniert danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798766</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798766</guid><dc:creator><![CDATA[borhany]]></dc:creator><pubDate>Mon, 26 Oct 2009 19:10:15 GMT</pubDate></item></channel></rss>