scorrpeio
Full Member level 5
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...
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.
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.