Thread: Emulating Constants w/ Individual Characters

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    14

    Question Emulating Constants w/ Individual Characters

    You say that title doesn't make sense? What? Oh, okay, I'll explain...

    In printf(), you can print a character by feeding it a hexidecimal number, as follows:

    Code:
    printf("%c", 0x61);
    This would produce the character a. Now, the complicated part. How would I emulate that hex constant if I had the first digit in one character, and the second in another character? Do I need to actively convert from the hex to decimal and feed that to the character? I'm perfectly able to do that conversion, I'm just using this as a learning experience.

    Thanks for any light you may be able to shed on the subject.
    -Aaron

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by daltore
    How would I emulate that hex constant if I had the first digit in one character, and the second in another character?
    Convert the hex digits to their corresponding int values (as in '0' to 0, 'A' to 10, etc). Now, you can compute your desired result by doing an 16 * a + b, where a and b are the int variables.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  3. How do you check how many characters a user has entered?
    By engstudent363 in forum C Programming
    Replies: 5
    Last Post: 04-08-2008, 06:05 AM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. check individual characters on input
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 09:56 PM

Tags for this Thread