CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Convert an Array of Characters to Array of hex equivalent

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
j_girl
Guest







Convert an Array of Characters to Array of hex equivalent
PostPosted: Tue Mar 14, 2006 12:12 pm     Reply with quote

Hi,

I need to convert an array of characters (Ex: char heater_write[6]= {'H','0','O','K','\r','\0'};) to an array that contains the hex equivalent of each character. (Ex: heater_hex = {4,8,3,0,4,F,4,B, etc...}). Does anyone know a simple algorithm to conquer this task?
Shocked

Thanks!
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Mar 14, 2006 12:17 pm     Reply with quote

It is hex. But 'H','0','O','K','\r','\0' is 0x48,0x30,0x4F,0x4B

that is h zero o k \r \0

Explain what your trying to do. Are you trying to print something?
mpfj



Joined: 09 Sep 2003
Posts: 95
Location: UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Mar 14, 2006 2:01 pm     Reply with quote

I think the OP is trying to convert an ASCII array to a "nibble" array.

Something like this should do the trick ...

Code:

char c;
char *src = &heater_write[0];
char *dest = &heater_hex[0];

for (c = *src; c != '\0'; c = *src++) {
   *dest++ = c >> 4;
   *dest++ = c & 0x0f;
}


This is just off the top of my head and untested, but it should give you a general idea as to what to do.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group