Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!ucla-cs!rutgers!njin!princeton!phoenix.Princeton.EDU!pfalstad From: pfalstad@phoenix.Princeton.EDU (Paul John Falstad) Newsgroups: comp.lang.c Subject: Re: Converting ascii hex values to hex bytes Message-ID: <3445@idunno.Princeton.EDU> Date: 19 Oct 90 03:07:13 GMT References: <298@cti1.UUCP> <31530022@hpcvia.CV.HP.COM> <1990Oct18.144906.5278@hellgate.utah.edu> Sender: news@idunno.Princeton.EDU Organization: Princeton University, Princeton, New Jersey Lines: 20 In article <1990Oct18.144906.5278@hellgate.utah.edu> msmith%peruvian.utah.edu@cs.utah.edu (Matthew Smith) writes: >does a printf %x, he'll get the decimal number in hex format, if he prints it >with a %c, he'll get the character with that ascii value. So, all he has to >do is read in the numbers into chars. If he is reading in the numbers as a >string, ie: '1','2','2', all he has to do is do a atoi, which will return >122 in a 16 bit integer, and then cast it into a char, and he'll have 122 in >1 char. ie: The 1 character ascii value of a number. To be picky, the cast is unnecessary, since chars are converted to ints anyway when used as function arguments. The following code works: printf("%c%c\n",65,'a'); to print two a's. I suggest putchar in this case, however. -- Paul Falstad, pfalstad@phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD And Dinsdale said, "You've been a naughty boy, Clement," and splits me nostrils open, and saws me leg off, and pulls me liver out. And I said, "My name's not Clement." And then he loses his temper. And he nails me head to the floor.