<?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[Integer in BCD wandeln]]></title><description><![CDATA[<p>Ich versuche verzweifelt eine Methode zu schreiben eine dreistellige Zahl (bis 999) als BCD zurückzugeben. Ich hab schon alles mögliche versucht mit Strings oder pow aber ohne Erfolg.</p>
<pre><code class="language-cpp">unsigned int TBCDCounter::Get_zaehlerstand(void)
{
 unsigned int zaehlstand = GetCounter();
 // ???
 return zaehlstand;
}
</code></pre>
<p>Bin für jeden Typ dankbar.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/106339/integer-in-bcd-wandeln</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Jul 2026 00:10:52 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/106339.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 08 Apr 2005 19:27:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Integer in BCD wandeln on Fri, 08 Apr 2005 19:27:43 GMT]]></title><description><![CDATA[<p>Ich versuche verzweifelt eine Methode zu schreiben eine dreistellige Zahl (bis 999) als BCD zurückzugeben. Ich hab schon alles mögliche versucht mit Strings oder pow aber ohne Erfolg.</p>
<pre><code class="language-cpp">unsigned int TBCDCounter::Get_zaehlerstand(void)
{
 unsigned int zaehlstand = GetCounter();
 // ???
 return zaehlstand;
}
</code></pre>
<p>Bin für jeden Typ dankbar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/762587</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/762587</guid><dc:creator><![CDATA[HardRock]]></dc:creator><pubDate>Fri, 08 Apr 2005 19:27:43 GMT</pubDate></item><item><title><![CDATA[Reply to Integer in BCD wandeln on Fri, 08 Apr 2005 20:14:53 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Hallo</p>
<p>du willst die Binärstellen einer Zahl in einen String schreiben?<br />
Das beste ist wohl Bitvergleich.<br />
Mein Vorschlag sieht so aus :</p>
<pre><code class="language-cpp">// Parameter Zahl ist die umzuwandelnde Zahl, Max ist die 
// maximale Vielfache von 2, in deinem Fall 1024
AnsiString BCD(unsigned int Zahl, unsigned int Max)
{
  AnsiString Result;
  if (Zahl &gt;= Max) return(&quot;&quot;);

  while (Max &gt; 0) // Alle Vielfachen von 2 im Bereich [Max, 1] durchgehen
  {
    if ((Zahl &amp; Max) == Max) // Wenn Stelle an aktuellem Vielfachen von 2 belegt
      Result += &quot;1&quot;;  // 1 anfügen
    else
      Result += &quot;0&quot;; // ansonten 0 anfügen
    Max &gt;&gt;= 1; // Bitshift für nächstkleinere Stelle 
    }
  return(Result);
  }

...
AnsiString x = BCD(100, 1024);
</code></pre>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/762604</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/762604</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Fri, 08 Apr 2005 20:14:53 GMT</pubDate></item><item><title><![CDATA[Reply to Integer in BCD wandeln on Fri, 08 Apr 2005 21:26:44 GMT]]></title><description><![CDATA[<p>HardRock schrieb:</p>
<blockquote>
<p>Ich versuche verzweifelt eine Methode zu schreiben eine dreistellige Zahl (bis 999) als BCD zurückzugeben.</p>
</blockquote>
<p>geht auch 4-stellig <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>#include &lt;stdio.h&gt; 

unsigned int bcd (int x)
{
    char b[16];
    sprintf (b, &quot;%04d&quot;, x);
    return b[3]-'0' | b[2]-'0'&lt;&lt;4 | b[1]-'0'&lt;&lt;8 | b[0]-'0'&lt;&lt;12;
}

int main() 
{ 
    printf (&quot;%x&quot;, bcd(9544));
    getchar();
    return 0; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/762613</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/762613</guid><dc:creator><![CDATA[net 0]]></dc:creator><pubDate>Fri, 08 Apr 2005 21:26:44 GMT</pubDate></item></channel></rss>