# biginteger print out in decimal for c

Hello,
I looking for a way to printout a big integer in decimal format from a array, the index 0 is the LSB.
example 0xBC 0x8C 0xB7  = 12029116
but how can i manege this (LSB -> 3C69845D9EECF3B4A5E26644076A1C363C69845D9EECF3B4A5E26644076A1C36949050 7B9AC1E2965370)
i don't wont to use big-number libraries like GMP, just looking for an easy method  for decimal printout
###### Who is Participating?

Commented:
That link I posted has code that will work perfectly for you. Either steal pieces for what you need or just use it outright (to do so you'll need to convert your hex to a std::string but you could do it easily like this:

``````std::string bn_to_string(bignum *nr)
{
char* str = new char[nr->size*2+1]; // +1 for null terminator
char* piece = new char[nr->size*2+1]; // +1 for null terminator

void *p_integer;
void *p_end;
str[0] = '\0'; //Start it empty
p_integer = nr->integer;
p_end = p_integer + nr->size;
p_integer--;
p_end--;
while(p_end > p_integer)
sprintf(piece, "%02X ", *((uint8_t *)p_end--)); //get next piece
strcat(str, piece);  //add it to the end
printf("\n");

return str; //Should convert to std::string, might need to use a cast or local var
}

``````
0

Commented:
How is the biginteger stored?
0

Commented:
Or check out how this guy did it and see if it works for you.
http://stackoverflow.com/questions/4735622/convert-large-hex-string-to-decimal-string
0

Commented:
Converting Binary (or Hexadecimal) integers to decimal is straight forward but tedious.

But if you don't want to use a BIGINT library, you will have to write some subset of it yourself.

You have to choose the format of you output result, probably digit array or character string.
And you have to write functions for 2^n (or 16^n) as well as addition and multiplication.
0

Author Commented:
the biginteger is stored in memory from lsb to msb bits in line the integer is from 2048 bit and up to 8192 bit i looking for a size independent method .
``````typedef struct
{
uint8_t  sign;
uint16_t size;
void *integer;
} bignum;
``````
``````void bn_init(bignum *nr, uint16_t size)
{
nr->integer = malloc(size);
nr->size = size;
nr->sign = 0; //set positiov (0) 1= negativ
}
``````
function for hex print out
``````void bn_print_msb(bignum *nr)
{
void *p_integer;
void *p_end;
p_integer = nr->integer;
p_end = p_integer + nr->size;
p_integer--;
p_end--;
while(p_end > p_integer)
printf("%02X ", *((uint8_t *)p_end--));
printf("\n");
}
``````
0

Author Commented:
the solutions is c++
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.