_Thomas
asked on
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 -> 3C69845D9EECF3B4A5E2664407 6A1C363C69 845D9EECF3 B4A5E26644 076A1C3694 9050 7B9AC1E2965370)
i don't wont to use big-number libraries like GMP, just looking for an easy method for decimal printout
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 -> 3C69845D9EECF3B4A5E2664407
i don't wont to use big-number libraries like GMP, just looking for an easy method for decimal printout
How is the biginteger stored?
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
http://stackoverflow.com/questions/4735622/convert-large-hex-string-to-decimal-string
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.
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.
ASKER
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 outvoid 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");
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the solutions is c++