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

Hex to Ascii Conversion

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



Joined: 29 Dec 2003
Posts: 81

View user's profile Send private message

Hex to Ascii Conversion
PostPosted: Thu Jan 08, 2004 5:36 pm     Reply with quote

Hi

I have an 8bytes data in an array, say array1[8] which contains the ff:
0xF1 0xDD 0x66 0x04 0xA3 0xDE 0x9B 0x0D ---> all in hex

I want to convert this data into ascii as:
F1DD6604A3DE9B0D ---> all in ascii character stored in an array2[16]

Anyone in the community who can provide help, snippet or any info.

Thank u.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Thu Jan 08, 2004 5:50 pm     Reply with quote

The easiest (but not necessarily the most efficient) way that comes to mind is:


Code:


byte I;
char Temp[2],array2[16];

for(I=0;I<8;I++)
{
    sprintf(Temp,"%X",array1[I]);
    Array2[I*2]=Temp[0];
    Array2[I*2+1]=Temp[1];
}

gerryc



Joined: 14 Mar 2004
Posts: 3
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Sun Mar 14, 2004 4:40 am     Reply with quote

Hi,

Code:
const char HEX[] = {0123456789ABCDEF};

char Array1[8], Array2[16];

for(i = 0; i < 8; i++) {
     Array2[i*2] = HEX[Array1[i] >> 4];
     Array2[(i*2)+1] = HEX[Array1[i] & 0x0f];
     }

HTH

Gerry
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