<?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[sprintf(buffer, &amp;quot;%03X&amp;quot;, tmp) in C++]]></title><description><![CDATA[<p>Ich moechte gern <code>sprintf(buffer, &quot;%03X&quot;, tmp)</code> in C++ realisieren. Im Moment transformiere ich normal mit <code>stringstream &lt;&lt; hex &lt;&lt; tmp</code> und mittels <code>substr</code> hole ich mir umstaendlich die letzten 3 Zeichen. Geht das einfacher? Boost-Loesungen sind willkommen, aber wuerde gern drauf verzichten.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/303840/sprintf-buffer-quot-03x-quot-tmp-in-c</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 05:37:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/303840.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 23 May 2012 15:29:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to sprintf(buffer, &amp;quot;%03X&amp;quot;, tmp) in C++ on Wed, 23 May 2012 15:29:06 GMT]]></title><description><![CDATA[<p>Ich moechte gern <code>sprintf(buffer, &quot;%03X&quot;, tmp)</code> in C++ realisieren. Im Moment transformiere ich normal mit <code>stringstream &lt;&lt; hex &lt;&lt; tmp</code> und mittels <code>substr</code> hole ich mir umstaendlich die letzten 3 Zeichen. Geht das einfacher? Boost-Loesungen sind willkommen, aber wuerde gern drauf verzichten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2214576</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2214576</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Wed, 23 May 2012 15:29:06 GMT</pubDate></item><item><title><![CDATA[Reply to sprintf(buffer, &amp;quot;%03X&amp;quot;, tmp) in C++ on Wed, 23 May 2012 15:40:24 GMT]]></title><description><![CDATA[<p>Das macht man mit fill und width:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cstdio&gt;
#include &lt;iomanip&gt;
using namespace std;
int main()
{
  int a = 12;
  printf(&quot;%03X&quot;, a);
  cout &lt;&lt; '\n' &lt;&lt; setfill('0') &lt;&lt; setw(3) &lt;&lt; hex &lt;&lt; a &lt;&lt; '\n';
}
</code></pre>
<p>P.S.: Lustig: Meine Standardbibliothek schreibt bei printf die Hex-Zahlen mit Großbuchstaben und bei cout mit Kleinbuchstaben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2214580</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2214580</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 23 May 2012 15:40:24 GMT</pubDate></item><item><title><![CDATA[Reply to sprintf(buffer, &amp;quot;%03X&amp;quot;, tmp) in C++ on Wed, 23 May 2012 15:58:16 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>P.S.: Lustig: Meine Standardbibliothek schreibt bei printf die Hex-Zahlen mit Großbuchstaben und bei cout mit Kleinbuchstaben.</p>
</blockquote>
<p>printf schreibt bei %X mit Groß- und bei %x mit Kleinbuchstaben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2214588</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2214588</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Wed, 23 May 2012 15:58:16 GMT</pubDate></item><item><title><![CDATA[Reply to sprintf(buffer, &amp;quot;%03X&amp;quot;, tmp) in C++ on Wed, 23 May 2012 15:59:53 GMT]]></title><description><![CDATA[<p>Hmm, verstehe ich das jetzt falsch, ich hatte an so etwas gedacht:</p>
<pre><code class="language-cpp">number %= 4096;
char buffer[4] = {};
const char hexChars[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
for(int i=2;i&gt;=0;--i)
{
    buffer[i]=hexChars[number%16];
    number/=16;
}
</code></pre>
<p>P.S.: Lustig: Meine Standardbibliothek schreibt bei printf die Hex-Zahlen mit Großbuchstaben und bei cout mit Kleinbuchstaben.[/quote]</p>
<pre><code class="language-cpp">printf(&quot;%03X&quot;, a);
cout &lt;&lt; '\n' &lt;&lt; std::uppercase &lt;&lt; setfill('0') &lt;&lt; setw(3) &lt;&lt; hex &lt;&lt; a &lt;&lt; '\n';
</code></pre>
<p>Komisch, bei mir ist es anders herum <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2214590</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2214590</guid><dc:creator><![CDATA[mapper]]></dc:creator><pubDate>Wed, 23 May 2012 15:59:53 GMT</pubDate></item><item><title><![CDATA[Reply to sprintf(buffer, &amp;quot;%03X&amp;quot;, tmp) in C++ on Wed, 23 May 2012 16:00:53 GMT]]></title><description><![CDATA[<p>Argh, natürlich kommt da ein kleines x bei printf hin.<br />
Naja, Bashar war sowieso schneller.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2214592</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2214592</guid><dc:creator><![CDATA[mapper]]></dc:creator><pubDate>Wed, 23 May 2012 16:00:53 GMT</pubDate></item><item><title><![CDATA[Reply to sprintf(buffer, &amp;quot;%03X&amp;quot;, tmp) in C++ on Wed, 23 May 2012 16:01:35 GMT]]></title><description><![CDATA[<p>mapper schrieb:</p>
<blockquote>
<p>Naja, Bashar war sowieso schneller.</p>
</blockquote>
<p>Aber ich kannte std::uppercase nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2214593</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2214593</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Wed, 23 May 2012 16:01:35 GMT</pubDate></item><item><title><![CDATA[Reply to sprintf(buffer, &amp;quot;%03X&amp;quot;, tmp) in C++ on Wed, 23 May 2012 21:48:52 GMT]]></title><description><![CDATA[<p>Danke fuer die Antworten, das spart schon mal eine Zeile. Leider muss ich immer noch einen Stream benutzen. Dachte eher an sowas wie <a href="http://en.cppreference.com/w/cpp/string/basic_string/to_string" rel="nofollow">to_string</a>, wo man die Basis mit angeben kann. Werde ich wohl selbst implementieren. Aber <code>uppercase</code> , <code>fill</code> und <code>setw</code> sind sehr hilfreich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2214711</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2214711</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Wed, 23 May 2012 21:48:52 GMT</pubDate></item></channel></rss>