Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. HEX to INT

HEX to INT

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Steven Richardson 0
    wrote on last edited by
    #1

    i have used INTtoHEX to convert some text to HEX but now I need to convert it back to read able text any cues? AnsiString EditText = RichEdit1->Lines->Text; for (int i=1;i<=EditText.Length();i++) { RichEdit2->Lines->Text = RichEdit2->Lines->Text + IntToHex(EditText[i],2); } RichEdit1->Lines->Text = ""; RichEdit1->Lines->Text = RichEdit2->Lines->Text; RichEdit2->Lines->Text = "";

    M M 2 Replies Last reply
    0
    • S Steven Richardson 0

      i have used INTtoHEX to convert some text to HEX but now I need to convert it back to read able text any cues? AnsiString EditText = RichEdit1->Lines->Text; for (int i=1;i<=EditText.Length();i++) { RichEdit2->Lines->Text = RichEdit2->Lines->Text + IntToHex(EditText[i],2); } RichEdit1->Lines->Text = ""; RichEdit1->Lines->Text = RichEdit2->Lines->Text; RichEdit2->Lines->Text = "";

      M Offline
      M Offline
      Mazdak
      wrote on last edited by
      #2

      There some articles in CP. Check this Mazy Don't Marry a Person You Can Live With... Marry Someone You Can Not Live Without

      1 Reply Last reply
      0
      • S Steven Richardson 0

        i have used INTtoHEX to convert some text to HEX but now I need to convert it back to read able text any cues? AnsiString EditText = RichEdit1->Lines->Text; for (int i=1;i<=EditText.Length();i++) { RichEdit2->Lines->Text = RichEdit2->Lines->Text + IntToHex(EditText[i],2); } RichEdit1->Lines->Text = ""; RichEdit1->Lines->Text = RichEdit2->Lines->Text; RichEdit2->Lines->Text = "";

        M Offline
        M Offline
        moliate
        wrote on last edited by
        #3

        Very crude, but i think this should work (send 2 chars at a time in your case)

        int Hex2Int(char* hex)
        {if (!*hex) return 0;

        int tmp = 0;
        if (*hex >= '0' && *hex <= '9')
        tmp = *hex - '0';
        else if (*hex >= 'A' && *hex <= 'F')
        tmp = *hex - 'A' + 10;
        else if (*hex >= 'a' && *hex <= 'f')
        tmp = *hex - 'a' + 10;

        return (tmp << (4*(strlen(hex)-1))) + Hex2Int(hex+sizeof(char));
        }

        /moliate

        S 1 Reply Last reply
        0
        • M moliate

          Very crude, but i think this should work (send 2 chars at a time in your case)

          int Hex2Int(char* hex)
          {if (!*hex) return 0;

          int tmp = 0;
          if (*hex >= '0' && *hex <= '9')
          tmp = *hex - '0';
          else if (*hex >= 'A' && *hex <= 'F')
          tmp = *hex - 'A' + 10;
          else if (*hex >= 'a' && *hex <= 'f')
          tmp = *hex - 'a' + 10;

          return (tmp << (4*(strlen(hex)-1))) + Hex2Int(hex+sizeof(char));
          }

          /moliate

          S Offline
          S Offline
          Steven Richardson 0
          wrote on last edited by
          #4

          sorry i am not sure how to implement this on to a decrypt button? when i press encrypt i get something like this: 68 65 72 65 73 20 77 68 61 74 20 68 61 70 70 65 6E 73 0D 0A and that says: heres what happens so i need the button to change it back from numbers to the text?

          M R 2 Replies Last reply
          0
          • S Steven Richardson 0

            sorry i am not sure how to implement this on to a decrypt button? when i press encrypt i get something like this: 68 65 72 65 73 20 77 68 61 74 20 68 61 70 70 65 6E 73 0D 0A and that says: heres what happens so i need the button to change it back from numbers to the text?

            M Offline
            M Offline
            moliate
            wrote on last edited by
            #5

            Perhaps it is not the best solution for you. Anyway, what the function does is taking a string like |6|8|\0| and turn it into the number 104 decimal - the ascii code for 'h'. If you can access each line as a string, you can send it to the function and get back a char. The string must be null-terminated, though. /moliate

            1 Reply Last reply
            0
            • S Steven Richardson 0

              sorry i am not sure how to implement this on to a decrypt button? when i press encrypt i get something like this: 68 65 72 65 73 20 77 68 61 74 20 68 61 70 70 65 6E 73 0D 0A and that says: heres what happens so i need the button to change it back from numbers to the text?

              R Offline
              R Offline
              Rick York
              wrote on last edited by
              #6

              Those are all ASCII character values displayed in hex. Try sprintf with a %c format specifier to get the text character. See the docs on sprintf for more details.

              S 1 Reply Last reply
              0
              • R Rick York

                Those are all ASCII character values displayed in hex. Try sprintf with a %c format specifier to get the text character. See the docs on sprintf for more details.

                S Offline
                S Offline
                Steven Richardson 0
                wrote on last edited by
                #7

                right heres what i have now: Encrypt: AnsiString EditText = RichEdit1->Lines->Text; for (int i=1;i<=EditText.Length();i++) { Form1->Tmp = Form1->Tmp + IntToHex(EditText[i],2); } RichEdit1->Lines->Text = ""; RichEdit1->Lines->Text = Form1->Tmp; Form1->Tmp = ""; Decrypt: AnsiString DeCrypt = Form1->RichEdit1->Lines->Text; int i = 1; int l = 2; for ( ;iTmp = DeCrypt[i]; Form1->Tmp = Form1->Tmp + DeCrypt[l]; Form1->RichEdit1->Lines->Append (Form1->Tmp); } so now: hello when encrypted = 68656C6C6F0D0A and on decrypt i get: 68 65 6C 6C 6F 0D 0A so tmp contains the temp string for each letter i now just need tmp to be converted?

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups