Text in Hex ausgeben

fatlip18

Grünschnabel
Hallo erstmal!

Hat jemand eine Ahnung wie ich einen Normalen Text in Hex-Zahlen darstellen kann !?
Gibts dazu eine Funktion?! glaub nicht oder?!:confused:

Thx im Voraus für eure Hilfe!
 
Hi.

Zum Beispiel so:
C++:
#include <iostream>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <string>

using namespace std;

int main() {
  string text = "Hallo, das ist ein String.";

  cout << hex << showbase;
  copy(text.begin(), text.end(),
       ostream_iterator<int>(cout, " "));

  cout << endl;
}
Die Ausgabe ist:
Code:
0x48 0x61 0x6c 0x6c 0x6f 0x2c 0x20 0x64 0x61 0x73 0x20 0x69 0x73 0x74 0x20 0x65
0x69 0x6e 0x20 0x53 0x74 0x72 0x69 0x6e 0x67 0x2e
Gruß
 
Aha. Das solltest du ruhig gleich am Anfang sagen um welche Sprache es geht.

In C ist das auch nicht viel schwieriger:
C:
#include <stdio.h>

int main() {
  char text[] = "Hallo, das ist ein String.";
  char* p;

  for (p = text; *p != '\0'; ++p) {
    printf("0x%0.2x", (int)*p);
  }

  return 0;
}
Die Ausgabe ist die gleiche wie vorher.

Gruß
 
Zurück