C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-22-2009, 09:35 AM   #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
daltore is offline   Reply With Quote
Old 03-22-2009, 09:41 AM   #2
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,359
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
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is online now   Reply With Quote
Reply

Tags
character, constant, convert, hexidecimal, variable

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A development process Noir C Programming 30 10-28-2009 04:24 AM
[URGENT] Getting warning: null character(s) ignored repeatedly headbr C Programming 10 07-10-2008 03:45 PM
How do you check how many characters a user has entered? engstudent363 C Programming 5 04-08-2008 06:05 AM
help with text input Alphawaves C Programming 8 04-08-2007 04:54 PM
check individual characters on input Unregistered C Programming 2 11-18-2001 09:56 PM


All times are GMT -6. The time now is 04:48 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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