Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Req - Binary to ASCII

Status
Not open for further replies.

jimbies

Member level 2
Joined
Jul 22, 2002
Messages
44
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
245
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.
 

pardal

Member level 5
Joined
Dec 29, 2001
Messages
81
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,288
Activity points
587
You can try a free product called GMT
(http://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.
 

Gomez

Full Member level 2
Joined
Feb 12, 2002
Messages
125
Helped
10
Reputation
20
Reaction score
3
Trophy points
1,298
Activity points
1,006
See source code for printf/sprintf.

Bye Gomez
 

Bus Master

Full Member level 3
Joined
Dec 9, 2001
Messages
187
Helped
9
Reputation
18
Reaction score
3
Trophy points
1,298
Location
Just behind You ;-)
Activity points
1,462
You can follow these steps, very simple and effective:

1- Convert the binary no. to BCD format, this leads to a groups of 4 bits in each group, each group value is from 0 to 9.

2- For every group, ADD 30 (decimal) to the 4bits value ==> ASCII of the digit. (e.g. A value of '1' will be '31' which is the ASCII of digit '1').

3- Repeat step 2 for every group, ==> ASCII values for digits to be generated and ready to be sent to LCD.

Hope this helps.
 

Darklord

Junior Member level 3
Joined
May 9, 2001
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
103
Can't find the gmtconvert zip file. Where is it exactly? Has anyone implemented it in C?
 

artem

Advanced Member level 4
Joined
May 22, 2003
Messages
1,350
Helped
126
Reputation
252
Reaction score
32
Trophy points
1,328
Location
Turkey
Activity points
13,461
Hi

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

*(pString + tpos + 1) = 0; // Put ending string delimiter

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 .
 

db69

Junior Member level 1
Joined
May 18, 2001
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
66
use sprinf ansi c function.

char *s;
unsigned int NumberToConvert;

sprintf(s,"%u",NumberToConvert);
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top