| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			chingB
 
 
  Joined: 29 Dec 2003 Posts: 81
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| Hex to Ascii Conversion | 
			 
			
				 Posted: Thu Jan 08, 2004 5:36 pm     | 
				     | 
			 
			
				
  | 
			 
			
				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 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Jan 08, 2004 5:50 pm     | 
				     | 
			 
			
				
  | 
			 
			
				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 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sun Mar 14, 2004 4:40 am     | 
				     | 
			 
			
				
  | 
			 
			
				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 | 
			 
		  | 
	
	
		  | 
	
	
		 |