How can we manage a 64 bits integer number to convert it to ASCCII value for LCD display. Does SPRINTF work with 'double' data type reguards.
How about this method. You will need to define an array of 38 elements. Each element is an unsigned long. Each element n is initialised to 2 to the power of n+1 and uses BCD representation.
= { 0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000016, 0x00000032....etc. }
Out of curiosity I came up with the following code to convert n binary digits to m decimal digits. This is the essence of a solution which may be readily adapted to your specific needs. The code includes a number of test examples. It compiles to reasonably efficient code, although making use of memory specific pointers would be much better than generic pointers.
#define BINARY_DIGITS 38 #define DECIMAL_DIGITS 12 // 1 2 3 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 xdata unsigned char big_binary_00[ BINARY_DIGITS ] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; xdata unsigned char big_binary_01[ BINARY_DIGITS ] = { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; xdata unsigned char big_binary_10[ BINARY_DIGITS ] = { 0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; xdata unsigned char big_binary_16[ BINARY_DIGITS ] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; xdata unsigned char big_binary_38[ BINARY_DIGITS ] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }; xdata unsigned char big_binary_xx[ BINARY_DIGITS ] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }; xdata unsigned char big_decimal[ DECIMAL_DIGITS ]; void conversion( unsigned char *binary, unsigned char *decimal ) { unsigned char loop; unsigned char outer_loop; unsigned char *d; unsigned char *t; unsigned char carry = 0; unsigned char temp[ DECIMAL_DIGITS ]; // // Initialise Data // loop = DECIMAL_DIGITS; d = decimal; t = &temp[ 0 ]; do { *t = 0; t++; *d = 0; d++; }while( --loop != 0 ); temp[ 0 ] = 1; outer_loop = BINARY_DIGITS; do { if( *binary != 0 ) { // // Set d to d plus t // loop = DECIMAL_DIGITS; carry = 0; t = &temp[ 0 ]; d = &decimal[ 0 ]; do { *d = (*d + *t) + carry; if( *d < 10 ) { carry = 0; } else { *d = *d - 10; carry = 1; } d++; t++; }while( --loop != 0 ); } // // Double the BCD value in t // loop = DECIMAL_DIGITS; carry = 0; t = &temp[ 0 ]; do { *t = (*t * 2) + carry; if( *t < 10 ) { carry = 0; } else { *t = *t - 10; carry = 1; } t++; }while( --loop != 0 ); binary++; }while( --outer_loop != 0 ); } main( void ) { conversion( &big_binary_00, &big_decimal ); conversion( &big_binary_01, &big_decimal ); conversion( &big_binary_10, &big_decimal ); conversion( &big_binary_16, &big_decimal ); conversion( &big_binary_38, &big_decimal ); conversion( &big_binary_xx, &big_decimal ); conversion( &big_binary_xx, &big_decimal ); }