<?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[Umwandlung von 8 Bytes zu Integer 64 bits.]]></title><description><![CDATA[<p>Hallo,<br />
ich habe hier einen Code erstellt, der 8 einzelene Bytes in eine Integer-Zahl mit 64 bits (=8 Bytes) umwandelt. Der Code funktioniert vorwiegend unter MS Visual Studio. Aber er kann auch unter jeden anderem Betriebssystem oder Programmiersprache laufen, wenn dort Int64 unterstützt wird.</p>
<p>Ich bin allerdings für Verbesserungen bezüglich Felxibilität (z. B. beliebger Datentyp) oder Performance offen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Gruss</p>
<p>Thomas</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include&lt;fstream&gt;
#include&lt;limits.h&gt;
using namespace std;
// This code works with Microsoft Visual Studio. It´s not ANSI C++ code.

int main(void)
{
	//Representation of unsigned integer with 64 bit:
	// |64      |56      |48      |40      |32      |24      |16      |8       -&gt; bit number
	// 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 -&gt; binary
	// ---0---0 ---0---0 ---0---0 ---0---0 ---0---0 ---0---0 ---0---0 ---0---0 -&gt; hexadecimal 
	// ---b8--- ---b7--- ---b6--- ---b5--- ---b4--- ---b3--- ---b2--- ---b1--- -&gt; Byte number
	// 8 Bytes with 'b8' as the highest and 'b1' with the lowest byte.
	const unsigned __int64 uInt64Max = ULLONG_MAX  ; /*maximum unsigned __int64 value */
	unsigned __int64 n64Result = uInt64Max;
	unsigned __int64 b8, b7, b6, b5, b4, b3, b2, b1; // Be careful ! These variables have to be in the range between 0 and 255 !!!!

	b8 = (unsigned char)255; // Highest Byte (64...55)
	b7 = (unsigned char)255;  
	b6 = (unsigned char)255;
	b5 = (unsigned char)255; 
	b4 = (unsigned char)255; 
	b3 = (unsigned char)255;  
	b2 = (unsigned char)255;
	b1 = (unsigned char)255; // Lowest Byte (8...1)

				   // |64      |56      |48      |40      |32      |24      |16      |8 
	b8 = b8 &lt;&lt; 56; // xxxxxxxx 00000000 00000000 00000000 00000000 00000000 00000000 00000000
	b7 = b7 &lt;&lt; 48; // 00000000 xxxxxxxx 00000000 00000000 00000000 00000000 00000000 00000000
	b6 = b6 &lt;&lt; 40; // 00000000 00000000 xxxxxxxx 00000000 00000000 00000000 00000000 00000000
	b5 = b5 &lt;&lt; 32; // 00000000 00000000 00000000 xxxxxxxx 00000000 00000000 00000000 00000000
	b4 = b4 &lt;&lt; 24; // 00000000 00000000 00000000 00000000 xxxxxxxx 00000000 00000000 00000000
	b3 = b3 &lt;&lt; 16; // 00000000 00000000 00000000 00000000 00000000 xxxxxxxx 00000000 00000000
	b2 = b2 &lt;&lt;  8; // 00000000 00000000 00000000 00000000 00000000 00000000 xxxxxxxx 00000000
	//b1              00000000 00000000 00000000 00000000 00000000 00000000 00000000 xxxxxxxx

	cout &lt;&lt; &quot;b8= &quot; &lt;&lt; b8 &lt;&lt; &quot; b7= &quot; &lt;&lt; b7 &lt;&lt; &quot; b6= &quot; &lt;&lt; b6 &lt;&lt; &quot; b5= &quot; &lt;&lt; b5
		 &lt;&lt; &quot;b4= &quot; &lt;&lt; b4 &lt;&lt; &quot; b3= &quot; &lt;&lt; b3 &lt;&lt; &quot; b2= &quot; &lt;&lt; b2 &lt;&lt; &quot; b1= &quot; &lt;&lt; b1 &lt;&lt; endl;

	n64Result = b8 + b7 + b6 + b5 + b4 + b3 + b2 + b1;

	cout &lt;&lt; &quot;result: n64Result= &quot; &lt;&lt; n64Result &lt;&lt; endl;

	cin.get();

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/144856/umwandlung-von-8-bytes-zu-integer-64-bits</link><generator>RSS for Node</generator><lastBuildDate>Wed, 02 Sep 2026 19:34:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/144856.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 Apr 2006 14:30:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Umwandlung von 8 Bytes zu Integer 64 bits. on Sat, 22 Apr 2006 14:30:12 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe hier einen Code erstellt, der 8 einzelene Bytes in eine Integer-Zahl mit 64 bits (=8 Bytes) umwandelt. Der Code funktioniert vorwiegend unter MS Visual Studio. Aber er kann auch unter jeden anderem Betriebssystem oder Programmiersprache laufen, wenn dort Int64 unterstützt wird.</p>
<p>Ich bin allerdings für Verbesserungen bezüglich Felxibilität (z. B. beliebger Datentyp) oder Performance offen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Gruss</p>
<p>Thomas</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include&lt;fstream&gt;
#include&lt;limits.h&gt;
using namespace std;
// This code works with Microsoft Visual Studio. It´s not ANSI C++ code.

int main(void)
{
	//Representation of unsigned integer with 64 bit:
	// |64      |56      |48      |40      |32      |24      |16      |8       -&gt; bit number
	// 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 -&gt; binary
	// ---0---0 ---0---0 ---0---0 ---0---0 ---0---0 ---0---0 ---0---0 ---0---0 -&gt; hexadecimal 
	// ---b8--- ---b7--- ---b6--- ---b5--- ---b4--- ---b3--- ---b2--- ---b1--- -&gt; Byte number
	// 8 Bytes with 'b8' as the highest and 'b1' with the lowest byte.
	const unsigned __int64 uInt64Max = ULLONG_MAX  ; /*maximum unsigned __int64 value */
	unsigned __int64 n64Result = uInt64Max;
	unsigned __int64 b8, b7, b6, b5, b4, b3, b2, b1; // Be careful ! These variables have to be in the range between 0 and 255 !!!!

	b8 = (unsigned char)255; // Highest Byte (64...55)
	b7 = (unsigned char)255;  
	b6 = (unsigned char)255;
	b5 = (unsigned char)255; 
	b4 = (unsigned char)255; 
	b3 = (unsigned char)255;  
	b2 = (unsigned char)255;
	b1 = (unsigned char)255; // Lowest Byte (8...1)

				   // |64      |56      |48      |40      |32      |24      |16      |8 
	b8 = b8 &lt;&lt; 56; // xxxxxxxx 00000000 00000000 00000000 00000000 00000000 00000000 00000000
	b7 = b7 &lt;&lt; 48; // 00000000 xxxxxxxx 00000000 00000000 00000000 00000000 00000000 00000000
	b6 = b6 &lt;&lt; 40; // 00000000 00000000 xxxxxxxx 00000000 00000000 00000000 00000000 00000000
	b5 = b5 &lt;&lt; 32; // 00000000 00000000 00000000 xxxxxxxx 00000000 00000000 00000000 00000000
	b4 = b4 &lt;&lt; 24; // 00000000 00000000 00000000 00000000 xxxxxxxx 00000000 00000000 00000000
	b3 = b3 &lt;&lt; 16; // 00000000 00000000 00000000 00000000 00000000 xxxxxxxx 00000000 00000000
	b2 = b2 &lt;&lt;  8; // 00000000 00000000 00000000 00000000 00000000 00000000 xxxxxxxx 00000000
	//b1              00000000 00000000 00000000 00000000 00000000 00000000 00000000 xxxxxxxx

	cout &lt;&lt; &quot;b8= &quot; &lt;&lt; b8 &lt;&lt; &quot; b7= &quot; &lt;&lt; b7 &lt;&lt; &quot; b6= &quot; &lt;&lt; b6 &lt;&lt; &quot; b5= &quot; &lt;&lt; b5
		 &lt;&lt; &quot;b4= &quot; &lt;&lt; b4 &lt;&lt; &quot; b3= &quot; &lt;&lt; b3 &lt;&lt; &quot; b2= &quot; &lt;&lt; b2 &lt;&lt; &quot; b1= &quot; &lt;&lt; b1 &lt;&lt; endl;

	n64Result = b8 + b7 + b6 + b5 + b4 + b3 + b2 + b1;

	cout &lt;&lt; &quot;result: n64Result= &quot; &lt;&lt; n64Result &lt;&lt; endl;

	cin.get();

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1042616</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1042616</guid><dc:creator><![CDATA[Johnny2005]]></dc:creator><pubDate>Sat, 22 Apr 2006 14:30:12 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung von 8 Bytes zu Integer 64 bits. on Sat, 22 Apr 2006 14:50:05 GMT]]></title><description><![CDATA[<p>Wenns funktioniert ists ja ok.<br />
Du könntest das script noch für andere compiler bereitsstellen die vielleicht nicht _int64 sonder long long int als 64bit typ benutzen.<br />
Mit präprozessoranweisugen geht das ganz gut.</p>
<p>Man könnte das ganze noch in nen array packen der dann ne komplizierte schleife durchläuft, in meinen Augen wirds dann aber nicht schöner.</p>
<pre><code class="language-cpp">const unsigned __int64 uInt64Max = ULLONG_MAX  ; /*maximum unsigned __int64 value */
    unsigned __int64 n64Result = uInt64Max;
</code></pre>
<p>Da könnte man der variabel auch direkt ULLONG_MAX zuweisen.</p>
<p>//EDIT<br />
achja man könnte die zahlen ja auch vom user eingeben lassen.<br />
dann hätte das script mehr sinn.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1042644</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1042644</guid><dc:creator><![CDATA[Mario Sandler]]></dc:creator><pubDate>Sat, 22 Apr 2006 14:50:05 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung von 8 Bytes zu Integer 64 bits. on Sat, 22 Apr 2006 15:42:29 GMT]]></title><description><![CDATA[<p>Johnny2005 schrieb:</p>
<blockquote>
<p>Ich bin allerdings für Verbesserungen bezüglich Felxibilität (z. B. beliebger Datentyp) [...] offen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
</blockquote>
<p>Das macht man mit Templates. Hier mal ein kleiner Vorgeschmack, wie man so etwas lösen könnte (ich geh mal davon aus, dass du dich noch nie mit Templates beschäftigt hast):</p>
<pre><code class="language-cpp">#include &lt;stdexcept&gt;

template&lt;class SourceType, class TargetType&gt;
class Converter
{
public:
    template&lt;int ArraySize&gt;
    static TargetType Convert(SourceType source[ArraySize])
    {
    	if(ArraySize &gt; SizeRelation)
            throw std::invalid_argument(&quot;Array too big&quot;);
    	TargetType result = TargetType();

    	for(int i = SizeRelation - 1; i &gt;= 0; --i)
    		result += source[i] &lt;&lt; (SizeRelation - i - 1) * 8;

        return result;
    }

private:
    static const unsigned int SizeRelation = sizeof(TargetType)/sizeof(SourceType);
    Converter();
};

// Anwendung
#include &lt;iostream&gt;

int main()
{
	unsigned char a[] = { 5, 7, 9, 4};

	unsigned int e = Converter&lt;unsigned char, unsigned int&gt;::Convert&lt;4&gt;(a);

	std::cout &lt;&lt; e;
}
</code></pre>
<p>Edit: Sicherer gemacht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1042701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1042701</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Sat, 22 Apr 2006 15:42:29 GMT</pubDate></item></channel></rss>