Tulipmania
Newbie level 4

Hi,
I need help with this module . It's to convert a binary value to its BCD equivalent assigning each digit to an element of an array. For example the binary value (11111111=ff hex) is equivalent to( 255 ) decimal so the 5 digit is assigned to the first element of the array......second 5 is assigned to the next element and 2 is assigned to the third. the problem is that the module is able to assign only the first two digits and never gets to assign the third digit to the third element of the array.
I noted that while simulating the module..so what's wrong with it ?
the program;
#include<reg52.h>
void main (void)
{
int x; //Array Index
unsigned int binvalue=0x00ff; // Binary value to be converted & displayed
int INT_DIGITS[3]; // Declaration of Array of digits separated
int *INT_PTR; // Array Pointer
x=0; //Initializing the pointer to point the first element
do
{
INT_PTR = &INT_DIGITS[x];// set INT_PTR to point to indexed element in INT_DIGITS
*INT_PTR= (binvalue%10); // Assigning the ASCII value to the element
binvalue = binvalue/10;
++x;
}
while(binvalue >= 10);
}
I need help with this module . It's to convert a binary value to its BCD equivalent assigning each digit to an element of an array. For example the binary value (11111111=ff hex) is equivalent to( 255 ) decimal so the 5 digit is assigned to the first element of the array......second 5 is assigned to the next element and 2 is assigned to the third. the problem is that the module is able to assign only the first two digits and never gets to assign the third digit to the third element of the array.
I noted that while simulating the module..so what's wrong with it ?
the program;
#include<reg52.h>
void main (void)
{
int x; //Array Index
unsigned int binvalue=0x00ff; // Binary value to be converted & displayed
int INT_DIGITS[3]; // Declaration of Array of digits separated
int *INT_PTR; // Array Pointer
x=0; //Initializing the pointer to point the first element
do
{
INT_PTR = &INT_DIGITS[x];// set INT_PTR to point to indexed element in INT_DIGITS
*INT_PTR= (binvalue%10); // Assigning the ASCII value to the element
binvalue = binvalue/10;
++x;
}
while(binvalue >= 10);
}