Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

[SOLVED] ASCII to BCD converter code logic for changing number size

Status
Not open for further replies.

scorrpeio

Full Member level 5
Joined
Dec 26, 2006
Messages
286
Helped
10
Reputation
20
Reaction score
9
Trophy points
1,298
Activity points
3,496
I have to write a code to covert a number into its unpacked BCD format.

My function accepts the number (upto 32bit long) and the address of char array where its unpacked bcd need to be saved. The code is...
void ASCIIToBCD( unsigned long u32Value, volatile char *ptrDest)
*ptrDest++ = u32Value/1000000000; //10th digit '9'999999999 converted to BCD
32Value%=1000000000;

*ptrDest++ = u32Value/100000000; //9th digit 9'9'99999999 converted to BCD
u32Value%=100000000;

*ptrDest++ = u32Value/10000000; //8th digit 99'9'9999999 converted to BCD and so on
u32Value%=10000000;

*ptrDest++ = u32Value/1000000;
u32Value%=1000000;

*ptrDest++ = u32Value/100000;
u32Value%=100000;

*ptrDest++ = u32Value/10000;
u32Value%=10000;

*ptrDest++ = u32Value/1000;
u32Value%=1000;

*ptrDest++ = u32Value/100;
u32Value%=100;

*ptrDest++ = u32Value/10;
u32Value%=10;

*ptrDest++ = u32Value;


This code works absolutely fine.
However, the number which I will pass in the argument varies from 3digit to 12 digit.
Also, the numbers may need to be converted in format like XXX.XX

According to the number, the size of array (where its bcd is stored) varies.
For ex, for a number having 10digit, I will have array of size 10
But, for a number having 4 digit, I will have array of size 4 only.

So, this function may not work as it is for above conditions.
I can't imagine how to make this function serve these purposes.

---------- Post added at 07:44 ---------- Previous post was at 06:45 ----------

I have solved the issue.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top