We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hi: I want to use recursion function to transform a integer from binary form to ascii form. But the result is wrong.I don't why ,please help to analyse.
soure code:
void binary_to_ascii(unsigned int value) { unsigned int quotient; quotient = value/10; if(quotient !=0 ) binary_to_ascii(quotient); putchar(value%10+'0'); } int main() { while(1){ binary_to_ascii(4267); } }
I want to produce characters '4','2','6','7' in sequence. but the result is '4','4','4'. I don't know what is wrong with my code.
http://www.keil.com/support/man/docs/c51/c51_le_reentrantfuncs.htm
* Small model reentrant functions simulate the reentrant stack in idata memory. * Compact model reentrant functions simulate the reentrant stack in pdata memory. * Large model reentrant functions simulate the reentrant stack in xdata memory.
Yes, I know it can be done; what I said was that I thought it was a bad idea to do it - for the reasons stated!
You are right. But in general I think, an unlimited recursion is a bad idea. In other case, the maximum size of the required stack is known.
I have used reentrant ,but the result always lack one charater. I want the result is '4','2','6','7', but the actual outcome is '4','2','6'. the '7' disappears. why?
void binary_to_ascii(unsigned int value reentrant
{
unsigned int quotient; quotient = value/10; if(quotient !=0 ) binary_to_ascii(quotient); putchar(value%10+'0');
}
int main() { while(1){ binary_to_ascii(4267); } }