Thanks for the correction. :) Actually, the original code was from a working 4 digit int to bcd conversion and was cut and pasted. I just added the 4th digit without rechecking the code. Reggie ----- Original Message ----- From: "Andrew Warren" To: Sent: Monday, June 02, 2003 6:26 PM Subject: Re: [PIC]: Integer to char > Reggie Berdin wrote: > > > Try: > > > > unsigned char bcd[5]; > > void int2bcd(unsigned int i) > > { > > bcd[0]=bcd[1]=bcd[2]=bcd[3]='0'; > > while (i>=10000) { > > i-=10000; > > ++bcd[0]; > > } > > while (i>=1000) { > > i-=1000; > > ++bcd[1]; > > } > > while (i>=100) { > > i-=100; > > ++bcd[2]; > > } > > bcd[4] = i & 0xFF; > > while (bcd[3]>=10) { > > bcd[4]-=10; > > ++bcd[3]; > > } > > bcd[4]+='0'; > > } > > Reggie: > > As written, this code fails; to make it work, change: > > while (bcd[3]>=10) { > > to: > > while (bcd[4]>=10) { > > -Andy > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics