Link to home
Start Free TrialLog in
Avatar of _Thomas
_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 -> 3C69845D9EECF3B4A5E26644076A1C363C69845D9EECF3B4A5E26644076A1C36949050 7B9AC1E2965370)
i don't wont to use big-number libraries like GMP, just looking for an easy method  for decimal printout
Avatar of TommySzalapski
TommySzalapski
Flag of United States of America image

How is the biginteger stored?
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.
Avatar of _Thomas
_Thomas

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;

Open in new window

void bn_init(bignum *nr, uint16_t size)
{
	nr->integer = malloc(size);
  	nr->size = size;
  	nr->sign = 0; //set positiov (0) 1= negativ
}

Open in new window

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");
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of TommySzalapski
TommySzalapski
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of _Thomas

ASKER

the solutions is c++