Hi All,
Before any of you stated that this is a duplicate topics, please read on because I can assure you it is not.
I had search numerous time for the solution and I still couldnt find any in the forum. So, please bear with me and read on.
Situation :
-
I got a reply from serial device with the following data (hex) :
30
44
42
45 -
I store all of the data into an array. Lets call it arrayA.
arrayA[0] | 0x30 |
---|---|
arrayA[1] | 0x44 |
arrayA[2] | 0x42 |
arrayA[3] | 0x45 |
- So, I need to convert that to ascii :
0x30 | 0x44 | 0x42 | 0x45 |
---|---|---|---|
0 | D | B | E |
I use this function :
int DecToHexStr (int Nilai)
{
if ((Nilai >=48) && (Nilai <=57)) //0-9
{
int HexNilai;
HexNilai = Nilai - '0';
return HexNilai;
}
else if ((Nilai >=65) && (Nilai <=70))
{
char HexNilaiB;
if (Nilai == 65) HexNilaiB = 65;
if (Nilai == 66) HexNilaiB = 66;
if (Nilai == 67) HexNilaiB = 67;
if (Nilai == 68) HexNilaiB = 68;
if (Nilai == 69) HexNilaiB = 69;
if (Nilai == 70) HexNilaiB = 70;
return HexNilaiB;
}
}
- So, we will get :
0DBE
But, "DBE" is still not stored as character.
5. How can I combined all of the "0","D","B","E" to become one hex number = 0x0DBE
6. And Convert it to decimal so that I can send the value trough serial port?