I need to realize an BCD to decimal converter over 8 decimal positions.
i declared an array to receive my keyboard entries (a decimal values like a calculator)
i have to convert it on binary code. To make it easy I decided to use a simply methode
ex 1,2,3,4,5,6,7,8 with BCD to dec8:
dec8= d'12345678' (dec8 must be 87 654 321)
dec8 = 1 * 1 // the result is 1
dec8= dec8 + (2*10)
dec8= dec8+ (3*1000)
...
the problem is when
Code: Select all
int start_array[8]= {1,2,3,4,5,6,7,8} ;
long int dec8=0;
void main() {
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
dec8 += saisie_val[0]; //the result dec8 = 1
dec8 += saisie_val[1]*10; //the result dec8 = 21
dec8 += saisie_val[2]*100;
dec8 += saisie_val[3]*1000; //the result dec8 = 321
dec8 += saisie_val[4]*10000; //the result dec8 = 4321
[color=#FF0040] dec8 += saisie_val[5]*100000; //the result dec8 = 214294956081[/color]
dec8 += saisie_val[6]*1000000;
dec8 += saisie_val[7]*10000000;
}
Please is there an other method more efficient to convert a BCD code over 8positions to binary code
Thanks a lot.