Emulating Constants w/ Individual Characters

This is a discussion on Emulating Constants w/ Individual Characters within the C Programming forums, part of the General Programming Boards category; You say that title doesn't make sense? What? Oh, okay, I'll explain... In printf(), you can print a character by ...

  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
    21,639
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 08:56 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21