<?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[Potenz als Integer]]></title><description><![CDATA[<p>Der folgende berechnet eine Array, für eine 7-Segment Anzeiger.<br />
Anstelle, das ich jede Ziffer einzeln berechne, will ich dies in einer Schleife lösen.<br />
Aber ich finde es übertrieben, das pow() ein double als Ergebniss liefert, da ich nur einen Integer brauche.<br />
Gibt es dafür eine elegante Lösung ? <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="😉"
    /><br />
Übrigens ist dieser Code für einen Arduino.</p>
<pre><code>const unsigned char digits[] = {
		0B00111111,  // = 0
		0B00000110,  // = 1
		0B01011011,  // = 2
		0B01001111,  // = 3
		0B01100110,  // = 4
		0B01101101,  // = 5
		0B01111101,  // = 6
		0B00000111,  // = 7
		0B01111111,  // = 8
		0B01100111,  // = 9
		};

const unsigned char maxSegment = 16;
unsigned char digit[maxSegment];

void displayNumber(int n) {
	n = abs(n);
	for (char i = 0; i &lt;= 4; i++) {
		digit[i] = digits[n % round(pow(10, i) * 10) / round(pow(10, i))];
	}

//	digit[0] =digits[ n % 10 / 1];
//	digit[1] =digits[ n % 100 / 10];
//	digit[2] =digits[ n % 1000 / 100];
//	digit[3] =digits[ n % 10000 / 1000];
//	digit[4] =digits[ n % 100000 / 10000];
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/338088/potenz-als-integer</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 14:13:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/338088.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 23 May 2016 16:33:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Potenz als Integer on Mon, 23 May 2016 16:33:50 GMT]]></title><description><![CDATA[<p>Der folgende berechnet eine Array, für eine 7-Segment Anzeiger.<br />
Anstelle, das ich jede Ziffer einzeln berechne, will ich dies in einer Schleife lösen.<br />
Aber ich finde es übertrieben, das pow() ein double als Ergebniss liefert, da ich nur einen Integer brauche.<br />
Gibt es dafür eine elegante Lösung ? <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="😉"
    /><br />
Übrigens ist dieser Code für einen Arduino.</p>
<pre><code>const unsigned char digits[] = {
		0B00111111,  // = 0
		0B00000110,  // = 1
		0B01011011,  // = 2
		0B01001111,  // = 3
		0B01100110,  // = 4
		0B01101101,  // = 5
		0B01111101,  // = 6
		0B00000111,  // = 7
		0B01111111,  // = 8
		0B01100111,  // = 9
		};

const unsigned char maxSegment = 16;
unsigned char digit[maxSegment];

void displayNumber(int n) {
	n = abs(n);
	for (char i = 0; i &lt;= 4; i++) {
		digit[i] = digits[n % round(pow(10, i) * 10) / round(pow(10, i))];
	}

//	digit[0] =digits[ n % 10 / 1];
//	digit[1] =digits[ n % 100 / 10];
//	digit[2] =digits[ n % 1000 / 100];
//	digit[3] =digits[ n % 10000 / 1000];
//	digit[4] =digits[ n % 100000 / 10000];
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2496699</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2496699</guid><dc:creator><![CDATA[Mathuas]]></dc:creator><pubDate>Mon, 23 May 2016 16:33:50 GMT</pubDate></item><item><title><![CDATA[Reply to Potenz als Integer on Mon, 23 May 2016 16:39:33 GMT]]></title><description><![CDATA[<p>Du hast doch auskommentiert schon eine andere Lösung.</p>
<p>Die kannst du problemlos in eine Schleife wandeln. Die Ziffer ist die Zahl modulo 10. Dann teilst du die Zahl durch 10 und machst von vorne weiter, solange die Zahl &gt; 0 ist (oder solange du bis 4 gezählt hast oder wie viele Ziffern du halt anzeigen kannst).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2496700</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2496700</guid><dc:creator><![CDATA[wob]]></dc:creator><pubDate>Mon, 23 May 2016 16:39:33 GMT</pubDate></item><item><title><![CDATA[Reply to Potenz als Integer on Mon, 23 May 2016 19:15:41 GMT]]></title><description><![CDATA[<p>Schau mal bei <a href="https://www.c-plusplus.net/forum/337998">https://www.c-plusplus.net/forum/337998</a> , wo es um itoa geht. Das ist deinem Problem sehr ähnlich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2496732</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2496732</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Mon, 23 May 2016 19:15:41 GMT</pubDate></item><item><title><![CDATA[Reply to Potenz als Integer on Tue, 24 May 2016 15:54:15 GMT]]></title><description><![CDATA[<p>DirkB schrieb:</p>
<blockquote>
<p>Schau mal bei <a href="https://www.c-plusplus.net/forum/337998">https://www.c-plusplus.net/forum/337998</a> , wo es um itoa geht. Das ist deinem Problem sehr ähnlich.</p>
</blockquote>
<p>Der Umweg über einen String, wäre eine gute Lösung.<br />
Dann könnte man auch Zahlen wie 1.23345E23 darstellen.</p>
<p>In C++ gibt es sicher auch eine Funktion wie FloatToStr, so wie es sie in Pascal gibt ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2496879</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2496879</guid><dc:creator><![CDATA[Mathuas]]></dc:creator><pubDate>Tue, 24 May 2016 15:54:15 GMT</pubDate></item><item><title><![CDATA[Reply to Potenz als Integer on Tue, 24 May 2016 15:58:52 GMT]]></title><description><![CDATA[<p>Mathuas schrieb:</p>
<blockquote>
<p>In C++ gibt es sicher auch eine Funktion wie FloatToStr, so wie es sie in Pascal gibt ?</p>
</blockquote>
<p>Es gibt eine Funktion to_string, die alle arithmetischen Typen in einen String umwandelt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2496880</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2496880</guid><dc:creator><![CDATA[bloat_to_bin]]></dc:creator><pubDate>Tue, 24 May 2016 15:58:52 GMT</pubDate></item><item><title><![CDATA[Reply to Potenz als Integer on Tue, 24 May 2016 17:01:58 GMT]]></title><description><![CDATA[<p>Was spricht gegen</p>
<pre><code>for (int i = 0, j = 10; i &lt; 5; ++i) {
	digit[i] = digits[n % j / (j / 10)];
	j *= 10;
}
</code></pre>
<p>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2496885</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2496885</guid><dc:creator><![CDATA[MatzeHHC]]></dc:creator><pubDate>Tue, 24 May 2016 17:01:58 GMT</pubDate></item><item><title><![CDATA[Reply to Potenz als Integer on Tue, 24 May 2016 16:51:37 GMT]]></title><description><![CDATA[<p>MatzeHHC schrieb:</p>
<blockquote>
<p>Was spricht gegen</p>
<pre><code>for (int i = 1, j = 10; i &lt;= 5; ++i) {
	digits[i] = digits[n % j / (j / 10)];
	j *= 10;
}
</code></pre>
<p>?</p>
</blockquote>
<p>Die falschen Indizes vom Array, zuviel Rechnerei</p>
<p>Für Positive n:</p>
<pre><code>for (int i = 0; i &lt; 5; ++i) {
    digits[i] = n % 10;
    n /=  10;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2496888</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2496888</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Tue, 24 May 2016 16:51:37 GMT</pubDate></item><item><title><![CDATA[Reply to Potenz als Integer on Tue, 24 May 2016 17:01:30 GMT]]></title><description><![CDATA[<p>DirkB schrieb:</p>
<blockquote>
<p>Die falschen Indizes vom Array</p>
</blockquote>
<p>Stimmt, habs korrigiert.</p>
<p>DirkB schrieb:</p>
<blockquote>
<p>zuviel Rechnerei</p>
</blockquote>
<p>Stimmt auch.</p>
<p>Ich wollte die Diskussion von dem to_string-Mist weglenken...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2496889</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2496889</guid><dc:creator><![CDATA[MatzeHHC]]></dc:creator><pubDate>Tue, 24 May 2016 17:01:30 GMT</pubDate></item></channel></rss>