<?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[Diffiziles Problemchen bei Umwandlung von int in Hex]]></title><description><![CDATA[<p>Ich lese eine Datei bytewise über char buffer aus und an einer bestimmten Stelle finde ich dann ein wave file. Um das wave file ganz heraulösen zu können muss, ich dessen länge wissen, die vom 5 - 8 byte (als little endian) des waves definiet ist. wie kann ich jetzt den HEXwert, der da steht umrechnen in int (Länge es Files).</p>
<p>jetz habe ich es so gelöst:</p>
<pre><code>const string intToHex( int i)
{
  ostringstream oss;
  oss &lt;&lt; hex &lt;&lt; i;
  return oss.str();
}

string vier = intToHex((int)buffer[i+7]);
string drei = intToHex((int)buffer[i+6]);
string zwei = intToHex((int)buffer[i+5]);
string eins = intToHex((int)buffer[i+4]);

string zusammen = &quot;0x&quot; + vier + drei + zwei + eins;

long int test = strtol(zusammen.c_str(), NULL, 16);
</code></pre>
<p>Das klappt auch. Jedoch wenn ich auf ein byte wie zb &quot;FC&quot; treffe, stimmt es alles nicht mehr, enn FC wird nach - 4 convertiert.</p>
<p>Kann mir vllt. jemand helfen? Wäre nett.</p>
<p>Tom</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/272631/diffiziles-problemchen-bei-umwandlung-von-int-in-hex</link><generator>RSS for Node</generator><lastBuildDate>Fri, 28 Aug 2026 18:28:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/272631.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 21 Aug 2010 21:28:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Diffiziles Problemchen bei Umwandlung von int in Hex on Sat, 21 Aug 2010 21:28:05 GMT]]></title><description><![CDATA[<p>Ich lese eine Datei bytewise über char buffer aus und an einer bestimmten Stelle finde ich dann ein wave file. Um das wave file ganz heraulösen zu können muss, ich dessen länge wissen, die vom 5 - 8 byte (als little endian) des waves definiet ist. wie kann ich jetzt den HEXwert, der da steht umrechnen in int (Länge es Files).</p>
<p>jetz habe ich es so gelöst:</p>
<pre><code>const string intToHex( int i)
{
  ostringstream oss;
  oss &lt;&lt; hex &lt;&lt; i;
  return oss.str();
}

string vier = intToHex((int)buffer[i+7]);
string drei = intToHex((int)buffer[i+6]);
string zwei = intToHex((int)buffer[i+5]);
string eins = intToHex((int)buffer[i+4]);

string zusammen = &quot;0x&quot; + vier + drei + zwei + eins;

long int test = strtol(zusammen.c_str(), NULL, 16);
</code></pre>
<p>Das klappt auch. Jedoch wenn ich auf ein byte wie zb &quot;FC&quot; treffe, stimmt es alles nicht mehr, enn FC wird nach - 4 convertiert.</p>
<p>Kann mir vllt. jemand helfen? Wäre nett.</p>
<p>Tom</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1942860</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1942860</guid><dc:creator><![CDATA[wtf]]></dc:creator><pubDate>Sat, 21 Aug 2010 21:28:05 GMT</pubDate></item><item><title><![CDATA[Reply to Diffiziles Problemchen bei Umwandlung von int in Hex on Sat, 21 Aug 2010 21:46:49 GMT]]></title><description><![CDATA[<p>string vier = intToHex((int)(unsigned char)buffer[i+7]);</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1942862</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1942862</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 21 Aug 2010 21:46:49 GMT</pubDate></item><item><title><![CDATA[Reply to Diffiziles Problemchen bei Umwandlung von int in Hex on Sat, 21 Aug 2010 21:59:24 GMT]]></title><description><![CDATA[<p>Es funktioniert! VIELEN DANK VOLKARD!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1942864</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1942864</guid><dc:creator><![CDATA[wtf]]></dc:creator><pubDate>Sat, 21 Aug 2010 21:59:24 GMT</pubDate></item><item><title><![CDATA[Reply to Diffiziles Problemchen bei Umwandlung von int in Hex on Sun, 22 Aug 2010 07:21:14 GMT]]></title><description><![CDATA[<p>Umständlicher als über die (doppelte) Stringkonvertierung geht es wohl kaum...</p>
<p>Nimm stattdessen:</p>
<pre><code class="language-cpp">unsigned char *b = static_cast&lt;unsigned char *&gt;(buffer);

int length = (b[i+7] &lt;&lt; 24) | (b[i+6] &lt;&lt; 16) | (b[i+5] &lt;&lt; 8) | b[i+4];
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1942899</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1942899</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Sun, 22 Aug 2010 07:21:14 GMT</pubDate></item><item><title><![CDATA[Reply to Diffiziles Problemchen bei Umwandlung von int in Hex on Tue, 24 Aug 2010 03:35:22 GMT]]></title><description><![CDATA[<p>Danke für den Tipp! Ich habe es jetzt schon so umgesetzt und es war mir auch klar, dass es auch viel effizienter geht. Das Programm braucht ich doch nur kurz für mich und es musste schnell gehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1943623</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1943623</guid><dc:creator><![CDATA[wtf]]></dc:creator><pubDate>Tue, 24 Aug 2010 03:35:22 GMT</pubDate></item></channel></rss>