Thread: How do I take an ascii character and print out the hex equivalent?

  1. #1
    Big Indian
    Guest

    How do I take an ascii character and print out the hex equivalent?

    I'd like to take the ascii characters 4 and 0 (so x34 and x30) and print out the ascii character for x40, how do I do this? I know my output will be some weird character that will probably make no sense on the screen when I output it, but that's ok.

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Take the characters 4 & 0 and put it in a string. Now convert it to an interger using atoi. Then you can treat that value as a hex value by writing your own conversion function and returning the integer that corresponds with the hex value. Now you can print that ascii character.

    e.g.
    int i;
    string[] = {'4', '0'};
    i = (int)atoi(string);
    i = HexToInt(i);
    printf("%c", i);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. count and print the frequency of each ASCII character
    By s_jsstevens in forum C Programming
    Replies: 3
    Last Post: 02-07-2011, 09:33 PM
  2. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  3. print hex value of character
    By Abda92 in forum C++ Programming
    Replies: 6
    Last Post: 09-10-2008, 04:28 PM
  4. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  5. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 08:26 PM