Thread: Ascii to hex

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    241

    Ascii to hex

    How can I convert a string to the hexadecimal equivelant?


    and then be able to convert it back?

    Using the C++ style of strings
    Last edited by bikr692002; 03-06-2006 at 01:57 PM.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    what equivalent? Is the string a number or?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    its like alpha characters (I'm trying to write my own excryption method)
    I think it goes like
    Code:
    Encrypt(string)
    {
    	string Encrypt(string);
    	int Length;
    	int Length2;
    	
    	Length=(string-length(Encrypt);
    	Length2=Length*2;
    	
    
    	inline bool atlHexEncode(
    		const BYTE *Encrypt,
    		int Length,
    		LPSTR HexEquiv,
    		int * Length2
    		)
    		throw();
    Of course its not finished yet, have alot of other things to do in the function
    Last edited by bikr692002; 03-06-2006 at 02:32 PM.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    I want it to go kindof like
    Input
    |
    Convert to Hex
    |
    Reverse String example: ag to ga
    |
    Convert to my own Table (Need to learn how to make one)
    |
    Multiply by random number 2 digits long
    |
    Store that random number as the 3rd and 4th characters in the string (but dont delete the other part of string)
    |
    Divide By random Number 3 digits long
    |
    Store that random number after the 5th character in the string (but dont delete the other part of string)
    |
    Divide new string by 5
    |
    output.

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Of course its not finished yet, have alot of other things to do in the function
    You have so many errors in the code you posted, it's not worth going over. I suggest you get a beginning C++ book.

    How can I convert a string to the hexadecimal equivelant?
    Data is stored on a computer in only one way: binary. There is no converting anything to anything else.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    I know I already corected themthat I could see(prob more), guesss you started the post before I did
    I guess I didnt follow http://msdn.microsoft.com/library/de...lhexdecode.asp right?

    I ment converting AB to (A equivilant)(B equivilant)
    Last edited by bikr692002; 03-06-2006 at 02:36 PM.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You want each character to be converted to its character code and that code converted to hex? So "Go" would convert to 47 6F?

    If that is the case, each character in the string is still a character with the character code as its value. You can use a loop that treats each character as an integral value and then convert that to a string in hex format. You can do this with a stringstream, sprintf or other ways.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Char to ASCII Hex Value Troubles
    By MattMik in forum C++ Programming
    Replies: 6
    Last Post: 03-25-2008, 02:17 PM
  2. Ascii to hex and hex to Ascii
    By beon in forum C Programming
    Replies: 1
    Last Post: 12-26-2006, 06:37 AM
  3. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  4. Encrypting text file with ASCII hex
    By supaben34 in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2005, 06:35 PM
  5. Hex to Ascii conversion
    By Ryno in forum C Programming
    Replies: 2
    Last Post: 03-24-2005, 09:16 AM