Need your help.
Does any one have a ready C routine to convert Binary > ASCII or
Binary > Decimal > Ascii ? I need to display an A to D result on a terminal. Thanks.
You can try a free product called GMT
(https://gmt.soest.hawaii.edu/). If you are on windows there is a pre-compiled version, otherwise you have to compile it yourself. Whithin it there
is a module called gmtconvert that does what you want.
Below is the one of the possible methods :
void num2str
(
INT16U tNumber, // Number to be converted
INT8U *pString // Pointer to sstring where converted number will be stored
)
{
INT8S tpos;
while(*pString != 0) // Goto end of string
pString++;
// Find number of bytes to encode number
if (tNumber < 10) tpos = 0; // 1 digit
else if(tNumber < 100) tpos = 1; // 2 digits
else if(tNumber < 1000) tpos = 2; // 3 digits
else if(tNumber < 10000) tpos = 3; // 4 digits
else tpos = 4; // 5 digits
for(;tpos >= 0 ; tpos--) // Convert number to string in loop
{
*(pString + tpos) = tNumber%10 + 0x30; // Calculate ascii digit and store it in string
tNumber = tNumber/10; // Divide the number by 10
}
}
It is for hex to BCD ASCII conversion . But it was right to use printf or sprintf as those are part of standard library , if you do not have some restrictions applying to theses functions (part of C standard ibrary ).
The hex to Hex ASCII is much more easy .