<?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[.BMP - OpenGL -&amp;gt; Hex to Dec Problem]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich bin gerade dabei Texture für OpenGL zu laden. Ich habe ein Problem bei der Umwandlung von Hex-Werten in Dezimalzahlen.</p>
<p>Z.B. möchte ich die Breite und Höhe der Bitmap-Datei auslesen.</p>
<pre><code class="language-cpp">ifs.seekg(18, ios_base::beg);
char *cwidth = new char[4];
ifs.read(cwidth, 4);
</code></pre>
<p>Nun steht im Hex-Editor für die Breite (256 px) 00-01-00-00. (Breite und Höhe wird in 4 Byte großen Blöcken gespeichert)<br />
Eigentlich ist der Wert 256 in Hex 100.</p>
<p>Wie kann ich nun die Hexzahl in eine Dezimalzahl umwandeln? Gibt es dafür eine fertige C++ Funktion? Ich habs schon mit <em>strtol</em> versucht.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/307161/bmp-opengl-gt-hex-to-dec-problem</link><generator>RSS for Node</generator><lastBuildDate>Fri, 07 Aug 2026 18:05:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/307161.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 18 Aug 2012 15:18:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to .BMP - OpenGL -&amp;gt; Hex to Dec Problem on Sat, 18 Aug 2012 15:18:42 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich bin gerade dabei Texture für OpenGL zu laden. Ich habe ein Problem bei der Umwandlung von Hex-Werten in Dezimalzahlen.</p>
<p>Z.B. möchte ich die Breite und Höhe der Bitmap-Datei auslesen.</p>
<pre><code class="language-cpp">ifs.seekg(18, ios_base::beg);
char *cwidth = new char[4];
ifs.read(cwidth, 4);
</code></pre>
<p>Nun steht im Hex-Editor für die Breite (256 px) 00-01-00-00. (Breite und Höhe wird in 4 Byte großen Blöcken gespeichert)<br />
Eigentlich ist der Wert 256 in Hex 100.</p>
<p>Wie kann ich nun die Hexzahl in eine Dezimalzahl umwandeln? Gibt es dafür eine fertige C++ Funktion? Ich habs schon mit <em>strtol</em> versucht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2243136</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2243136</guid><dc:creator><![CDATA[aptem]]></dc:creator><pubDate>Sat, 18 Aug 2012 15:18:42 GMT</pubDate></item><item><title><![CDATA[Reply to .BMP - OpenGL -&amp;gt; Hex to Dec Problem on Sat, 18 Aug 2012 15:35:47 GMT]]></title><description><![CDATA[<p>Haha, das geht ganz einfach:</p>
<pre><code class="language-cpp">std::string str = &quot;0xFF&quot;; 
        std::istringstream stream(str); 
        int result; 
        stream &gt;&gt; std::hex &gt;&gt; result;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2243139</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2243139</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 18 Aug 2012 15:35:47 GMT</pubDate></item><item><title><![CDATA[Reply to .BMP - OpenGL -&amp;gt; Hex to Dec Problem on Sat, 18 Aug 2012 15:37:52 GMT]]></title><description><![CDATA[<p>BMP-Dateien werden wohl binär kodiert sein. Was willst du da von Hex nach Dezimal konvertieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2243142</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2243142</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sat, 18 Aug 2012 15:37:52 GMT</pubDate></item><item><title><![CDATA[Reply to .BMP - OpenGL -&amp;gt; Hex to Dec Problem on Sat, 18 Aug 2012 15:37:57 GMT]]></title><description><![CDATA[<p>Wozu umwandeln ??</p>
<pre><code>ifs.seekg(18, std::ios_base::beg);
int cwidth;
ifs.read(reinterpret_cast&lt;char*&gt;(&amp;cwidth), 4);
</code></pre>
<p>Kurt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2243143</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2243143</guid><dc:creator><![CDATA[ZuK]]></dc:creator><pubDate>Sat, 18 Aug 2012 15:37:57 GMT</pubDate></item><item><title><![CDATA[Reply to .BMP - OpenGL -&amp;gt; Hex to Dec Problem on Sat, 18 Aug 2012 17:01:40 GMT]]></title><description><![CDATA[<p>Es gibt keine Hex-Zahlen. Das ist nur eine Darstellung, genau wie Dezimalzahlen eine Darstellung sind.</p>
<p>Es gibt in C++ keine fertige Funktion für so etwas, aber die Bytes lassen sich ganz leicht wieder zusammensetzen:</p>
<pre><code class="language-cpp">unsigned char width_bytes[4];
ifs.read(reinterpret_cast&lt;char *&gt;(width_bytes), sizeof(width_bytes));

//der korrekte Typ aus [c]&lt;cstdint&gt;[/c]
typedef std::uint_fast32_t UInt32;

auto const width =
	(static_cast&lt;UInt32&gt;(width_bytes[0])) |
	(static_cast&lt;UInt32&gt;(width_bytes[1]) &lt;&lt; 8) |
	(static_cast&lt;UInt32&gt;(width_bytes[2]) &lt;&lt; 16) |
	(static_cast&lt;UInt32&gt;(width_bytes[3]) &lt;&lt; 24);
</code></pre>
<p>ZuK schrieb:</p>
<blockquote>
<p>Wozu umwandeln ??</p>
<pre><code>ifs.seekg(18, std::ios_base::beg);
int cwidth;
ifs.read(reinterpret_cast&lt;char*&gt;(&amp;cwidth), 4);
</code></pre>
<p>Kurt</p>
</blockquote>
<p>Mögliche Fehler:</p>
<ul>
<li><code>int</code> ist kleiner als 4 -&gt; &quot;buffer overflow&quot;</li>
<li><code>int</code> ist größer als 4 -&gt; in den restlichen Bytes steht Müll, weil nicht initialisiert</li>
<li><code>int</code> ist nicht Little-Endian<br />
Hässlich:<br />
- die Größe ist eine Magic Number</li>
<li><code>reinterpret_cast</code> von <code>int *</code> auf <code>char *</code></li>
<li><code>signed</code> , wenn das gar nicht erforderlich ist</li>
</ul>
]]></description><link>https://www.c-plusplus.net/forum/post/2243145</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2243145</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Sat, 18 Aug 2012 17:01:40 GMT</pubDate></item><item><title><![CDATA[Reply to .BMP - OpenGL -&amp;gt; Hex to Dec Problem on Sat, 18 Aug 2012 16:48:56 GMT]]></title><description><![CDATA[<blockquote>
<p>Mögliche Fehler:<br />
....</p>
<ul>
<li><code>int</code> ist nicht Little-Endian</li>
</ul>
</blockquote>
<p>Das sollten wir jetzt besser nicht diskutieren.<br />
Die Byteschieberei funktioniert <strong>nur</strong> wenn <strong>beides</strong> (File und System ) Little Endian ist.<br />
Der cast funktioniert auch wenn beides Big Endian ist.<br />
Kurt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2243153</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2243153</guid><dc:creator><![CDATA[ZuK]]></dc:creator><pubDate>Sat, 18 Aug 2012 16:48:56 GMT</pubDate></item><item><title><![CDATA[Reply to .BMP - OpenGL -&amp;gt; Hex to Dec Problem on Sat, 18 Aug 2012 16:59:42 GMT]]></title><description><![CDATA[<p>ZuK schrieb:</p>
<blockquote>
<blockquote>
<p>Mögliche Fehler:<br />
....</p>
<ul>
<li><code>int</code> ist nicht Little-Endian</li>
</ul>
</blockquote>
<p>Das sollten wir jetzt besser nicht diskutieren.<br />
Die Byteschieberei funktioniert <strong>nur</strong> wenn <strong>beides</strong> (File und System ) Little Endian ist.<br />
Der cast funktioniert auch wenn beides Big Endian ist.<br />
Kurt</p>
</blockquote>
<p>Äh, die Datei ist in Little Endian, da gibt es kein &quot;wenn&quot;.<br />
Meine Variante (Byte-Schieberei?) funktioniert dann auf jedem System.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2243156</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2243156</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Sat, 18 Aug 2012 16:59:42 GMT</pubDate></item><item><title><![CDATA[Reply to .BMP - OpenGL -&amp;gt; Hex to Dec Problem on Sat, 18 Aug 2012 16:58:17 GMT]]></title><description><![CDATA[<p>ZuK schrieb:</p>
<blockquote>
<p>Das sollten wir jetzt besser nicht diskutieren.<br />
Die Byteschieberei funktioniert <strong>nur</strong> wenn <strong>beides</strong> (File und System ) Little Endian ist.<br />
Der cast funktioniert auch wenn beides Big Endian ist.<br />
Kurt</p>
</blockquote>
<p><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="😕"
    /> Byteschieberei ist reine Mathematik und unabhängig von jedweder Endianess.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2243157</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2243157</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sat, 18 Aug 2012 16:58:17 GMT</pubDate></item><item><title><![CDATA[Reply to .BMP - OpenGL -&amp;gt; Hex to Dec Problem on Sat, 18 Aug 2012 17:37:01 GMT]]></title><description><![CDATA[<p>TyRoXx schrieb:</p>
<blockquote>
<p>Äh, die Datei ist in Little Endian, da gibt es kein &quot;wenn&quot;.<br />
Meine Variante (Byte-Schieberei?) funktioniert dann auf jedem System.</p>
</blockquote>
<p>Ja das stimmt. Sorry<br />
Kurt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2243163</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2243163</guid><dc:creator><![CDATA[ZuK]]></dc:creator><pubDate>Sat, 18 Aug 2012 17:37:01 GMT</pubDate></item><item><title><![CDATA[Reply to .BMP - OpenGL -&amp;gt; Hex to Dec Problem on Sat, 18 Aug 2012 17:54:09 GMT]]></title><description><![CDATA[<p>aptem schrieb:</p>
<blockquote>
<p>Hallo zusammen,</p>
<p>ich bin gerade dabei Texture für OpenGL zu laden. Ich habe ein Problem bei der Umwandlung von Hex-Werten in Dezimalzahlen.</p>
<p>Z.B. möchte ich die Breite und Höhe der Bitmap-Datei auslesen.</p>
<pre><code class="language-cpp">ifs.seekg(18, ios_base::beg);
char *cwidth = new char[4];
ifs.read(cwidth, 4);
</code></pre>
<p>Nun steht im Hex-Editor für die Breite (256 px) 00-01-00-00. (Breite und Höhe wird in 4 Byte großen Blöcken gespeichert)<br />
Eigentlich ist der Wert 256 in Hex 100.</p>
<p>Wie kann ich nun die Hexzahl in eine Dezimalzahl umwandeln? Gibt es dafür eine fertige C++ Funktion? Ich habs schon mit <em>strtol</em> versucht.</p>
</blockquote>
<p>umwandeln? vergiss es! siehe beitrag von ZuK, aber ruck-zuck! <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2243168</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2243168</guid><dc:creator><![CDATA[bitmapp0r]]></dc:creator><pubDate>Sat, 18 Aug 2012 17:54:09 GMT</pubDate></item></channel></rss>