CString to Hex



  • moin

    ich hab nen

    CString a = "FF";

    und möchte daraus ein

    char b = '\xff' machen

    die bekomm ich irgendwie nicht hin -.-

    ich habs soweit das mir in nem CString tmp = "0xff" stehn aber daraus dann '\xff' zu machen da haperts bei mir etwas

    also meine bisherige Funktion

    char hex (CString wert){
      char ret;
    
      int w;
      _stscanf(wert,"%x",&w);
      CString s;
      s.Format(_T("0x%02x"), w);
      AfxMessageBox(s);
    
      //hier müsste jetzt die kontertierung von CString in char hin
    
      return ret;
    
    }
    

    wie bekomm ich das hin ???
    thx LT


  • Mod

    Dein w ist Dein Ergebnis! Was willst Du noch konvertieren?

    Einfach:

    return w;
    

    besser

    return static_cast<char>(w);
    

    BTW: scanf würde ich bei so etwas nie benutzen. Eher strtoul, die ist auch weitaus schneller.


Anmelden zum Antworten