hi all,
before of stated duplicate topics, please read on because can assure not.
i had search numerous time solution , still couldnt find in forum. so, please bear me , read on.
situation :
1. got reply serial device following data (hex) :
2. store of data array. lets call arraya.
3. so, need convert ascii :
i use function :
4. so, :
but, "dbe" still not stored character.
5. how can combined of "0","d","b","e" become 1 hex number = 0x0dbe
6. , convert decimal can send value trough serial port?
before of stated duplicate topics, please read on because can assure not.
i had search numerous time solution , still couldnt find in forum. so, please bear me , read on.
situation :
1. got reply serial device following data (hex) :
30 | 44 | 42 | 45 |
2. store of data array. lets call arraya.
arraya[0] | 0x30 |
arraya[1] | 0x44 |
arraya[2] | 0x42 |
arraya[3] | 0x45 |
3. so, need convert ascii :
0x30 | 0x44 | 0x42 | 0x45 |
0 | d | b | e |
i use function :
code: [select]
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;
}
}
4. so, :
0dbe |
5. how can combined of "0","d","b","e" become 1 hex number = 0x0dbe
6. , convert decimal can send value trough serial port?
Arduino Forum > Using Arduino > Programming Questions > Hex To Ascii String
arduino
Comments
Post a Comment