|
|
View previous topic :: View next topic |
Author |
Message |
j_girl Guest
|
Convert an Array of Characters to Array of hex equivalent |
Posted: Tue Mar 14, 2006 12:12 pm |
|
|
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?
Thanks! |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Tue Mar 14, 2006 12:17 pm |
|
|
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
|
|
Posted: Tue Mar 14, 2006 2:01 pm |
|
|
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. |
|
|
|
|
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
|