<?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 String -&amp;gt; Hex]]></title><description><![CDATA[<p>Hallo Zusammen,</p>
<p>ich habe ein Problem bei Umwandlung!</p>
<p>ich habe so ein Hex-Wert: 0x89<br />
Das ist aber ein String.<br />
Ich entferne 0x und bleiben noch 89 übrig.</p>
<p>Bei Umstellung nach Hex, gibt er mir so was aus: FFFFFF89</p>
<p>Weiß jemand woran es liegen kann? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Gruß Studi</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/171252/umwandlung-string-gt-hex</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 09:07:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/171252.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 23 Jan 2007 20:39:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Umwandlung String -&amp;gt; Hex on Tue, 23 Jan 2007 20:39:03 GMT]]></title><description><![CDATA[<p>Hallo Zusammen,</p>
<p>ich habe ein Problem bei Umwandlung!</p>
<p>ich habe so ein Hex-Wert: 0x89<br />
Das ist aber ein String.<br />
Ich entferne 0x und bleiben noch 89 übrig.</p>
<p>Bei Umstellung nach Hex, gibt er mir so was aus: FFFFFF89</p>
<p>Weiß jemand woran es liegen kann? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Gruß Studi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1215549</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1215549</guid><dc:creator><![CDATA[studi]]></dc:creator><pubDate>Tue, 23 Jan 2007 20:39:03 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung String -&amp;gt; Hex on Tue, 23 Jan 2007 20:48:28 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Das liegt an deiner &quot;Umwandlung&quot;. Was daran falsch ist können wir dir nicht sagen, da du nicht erwähnt hast was du denn überhaupt zur Umwandlung benutzt.<br />
Desweiteren ist &quot;hex&quot; kein Datentyp.</p>
<p>Ich vermute du brauchst so was wie std::hex für den stringstream</p>
<p>/Edit : VCL-Sachen entfernt</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1215554</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1215554</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Tue, 23 Jan 2007 20:48:28 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung String -&amp;gt; Hex on Tue, 23 Jan 2007 21:30:14 GMT]]></title><description><![CDATA[<p>Hier der Code:</p>
<pre><code class="language-cpp">const int ChlProtocol::CreatePackage( const char* data,
                                      const unsigned int len,
                                      char* package,
                                      const unsigned int plen)
//len ist die Länge von data, *package ist was man zurückgibt
//data = &lt;ETX&gt;&lt;0x89&gt;&lt;'b'&gt;&lt;0xFF&gt;&lt;ESC&gt;&lt;'A'&gt;&lt;0x57&gt;&lt;STX&gt; //8 Zeichen ist plen, len ist 47
{	
 int i = 0;	
 char mydata[ MAXLEN_DATA_HL ];	//MAXLEN_DATA_HL = 47
 char *tmp;

 char *Token[ PACKAGE_SIZE_HL_ALL + 3 ];//PACKAGE_SIZE_HL_ALL = 8
 char buffer[4] = {'\0','\0','\0','\0'};	
 int  bufidx    = 0;	
 enum _myZeichen { eNone = 0, eChar, eHex, eCtrl } myZeichen;

 if( plen &lt; PACKAGE_SIZE_HL_ALL )
  return 0;		

 if( data == NULL || package == NULL )
  return 0;

// Datenbereich initialisieren
 memset( mydata, 0, MAXLEN_DATA_HL);		
 memcpy( mydata, data, len );				
 Token[0] = strtok(mydata, &quot;&lt;*&gt;&quot;);		

 do
  {
  // Zeichen init
  myZeichen = eNone;
  bufidx = 0;
  tmp = Token[i];

  while( *tmp != '&gt;' &amp;&amp; tmp != NULL)
  {
   if( myZeichen == eNone )
    {
     switch( *tmp )
     {
      case '\'': 
	myZeichen = eChar;
	break;
      case '0':
	myZeichen = eHex;
	break;
      case '&lt;':
	myZeichen = eNone;
	break;
      default:
	myZeichen = eCtrl;

      buffer[bufidx] = *tmp;
      bufidx++;
     }
   } 
   else
    {
    switch( myZeichen )
     {
      case eChar:
       package[i] = *tmp;
       *(tmp + 1) = '&gt;';
       break;
//--------- Ab hier stimmt was nicht!!!
      case eHex :
       // x löschen
       if( *tmp == 'x' )
       break;

      // char -&gt; int
      buffer[0] = (*tmp - '0');

      // HEX Char korigieren
      if( buffer[0] &gt; 9 )
       buffer[0] -= 7;

      // Wert berechnen
      if( bufidx == 0 )
	package[i] = buffer[0] * 16;
      else
      {
	package[i] += buffer[0];
	*(tmp + 1) = '&gt;';
      }
	bufidx++;
	break;
//-------- bis hier!!!
      case eCtrl:
	buffer[bufidx] = *tmp;
	bufidx++;
	if( bufidx &gt;= 3 )
	{	// Zeichenkette vollständig
	 if( strstr(buffer, &quot;SOH&quot;) != NULL )
           package[i] = 1;                  
	 else if( strstr(buffer, &quot;STX&quot;) != NULL )
           package[i] = 2;
	 else if( strstr(buffer, &quot;ETX&quot;) != NULL )
           package[i] = 3;
	 else if( strstr(buffer, &quot;EOT&quot;) != NULL )
	   package[i] = 4;
	 else if( strstr(buffer, &quot;ETB&quot;) != NULL )
	   package[i] = 17;
	 else if( strstr(buffer, &quot;ESC&quot;) != NULL )
	   package[i] = 27;
	 else
	   package[i] = 0;
	 *(tmp + 1) = '&gt;';
        }								
	break;
      case eNone:
	default:
	return 0;
     }
   }
    tmp++;
  }

  // next Token 
  i++;
  }while( (Token[i] = strtok(NULL, &quot;&lt;*&gt;&quot;)) != NULL);

  return i;
}
</code></pre>
<p>Ausgabe: &lt;3&gt;&lt;FFFFFF89&gt;&lt;62&gt;&lt;FFFFFFFF&gt;&lt;27&gt;&lt;41&gt;&lt;57&gt;&lt;2&gt;<br />
1. Wert OK<br />
2. Wert nicht OK!<br />
3. Wert OK<br />
4. Wert nicht OK!<br />
5. Wert OK<br />
6. Wert OK<br />
7. Wert OK</p>
<p>Gruß Studi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1215596</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1215596</guid><dc:creator><![CDATA[studi]]></dc:creator><pubDate>Tue, 23 Jan 2007 21:30:14 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung String -&amp;gt; Hex on Wed, 24 Jan 2007 14:35:14 GMT]]></title><description><![CDATA[<p>Package ist ein Zeiger auf char (Und da Dein Compiler das als signed char interpretiert geht der Wertebereich von -128 bis +127 (oder 0x7F). Alles was größer als 0x7F ist wird als negative Zahl interpretiert.<br />
Also einfach Package als unsigned char* definieren.</p>
<p>DJohn</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1216044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1216044</guid><dc:creator><![CDATA[DJohn]]></dc:creator><pubDate>Wed, 24 Jan 2007 14:35:14 GMT</pubDate></item></channel></rss>