@OP
1. Say, this is your hex number: 0x1c34 or any combination of 0 - 9, A - F or 0 - 9, a - f.
2. There are two bytes data in Step-1, and these are: 0x1c and 0x34 or 0x1C and 0x34. Here, 0x refers to hexadecimal base.
3. You want that every digit of the data of Step-2 should be transformed into its ASCII code. This is to say that 1 would be converted to 0x31 (hex), c would be transformed to 0x43 (hex) as per following ASCII table.
Figure-1: ASCII Table for the characters of English Language Alphabet
4. Let us see how we can obtain 0x31 for 1 from Fig-1 using C Codes.
(1) let us observe that: 0x31 = 0x30 + 0x01
(2) Form Step-4(1), it is deduced that that he ASCII code could be found by adding the hex digit with 0x30. That is -- the ASCII code of 1 is: ==> 0x01 + 0x30 = 0x31.
(3) For C, the ASCII code is: 0x43 ==> 0x0C + 0x37.
5. Based on the analysis of Step-4, we can form the following structure:
obtains 1st byte (0x1c) of the given number and save into variable byte x;.
Extract 1st digit (0x01 from left) of 0x1c and save into variable byte y;.
if(y <= 0x09)
{
y = y + 0x30; //y holds the ASCII code of any digit from 0 - 9 = 0x30 - 0x39 (note: 0x30 = '0')
}
else
{
y = y + 0x37; //y holds ASCII code of any digit from A - F (a - f) = 0x41 - 0x46 (note: 0x41 = 'A')
}
6. Finally, we can write as:
byte myData [] = {0x52, 0x6f, 0x73, 0x65, 0x74, 0x74, 0x61, 0x20, 0x43, 0x6f, 0x64, 0x65, 0x21};
char myASCII[26] = ""; //to hold the ASCII codes of the digits of the given number
byte x1 = sizeof(myData); //x1 = 13
for(int i = 0, j=0; i<x1, j<2*x1; i++, j++)
{
byte x = myData[i]; //x = 52
x = x>>4; //x=05
if(x <= 9)
{
x = x + 0x30; //x holds ASCII codes of any digit from 0 - 9 as the case be
myASCII [j] = x; //myASCII[0] holds ASCII codes of digits 0 - 9 as the case be
}
else
{
x = x + 0x37; // x = ASCII code of digits: A - F
myASCII [j] = x; //myASCII[0] holds ASCII codes of digits: A - F as the case be
}
}