我有四个无符号的32位整数,表示无符号的128位整数,以小端顺序表示:
typedef struct {
unsigned int part[4];
} bigint_t;
Run Code Online (Sandbox Code Playgroud)
我想将此数字转换为十进制字符串表示形式并将其输出到文件中.
现在,我正在使用一个bigint_divmod10函数将数字除以10,跟踪余数.我重复调用此函数,将余数作为数字输出,直到数字为零.这很慢.这是最快的方法吗?如果是这样,有没有一种聪明的方法来实现我没有看到的这个功能?我试过看GMP get_str.c,但我发现它非常难以理解.
编辑:这是我能够为divmod10函数提供的最快的代码:
static unsigned uint128_divmod10(uint128 *value)
{
unsigned int a = value->word[3];
unsigned int b = value->word[2];
unsigned int c = value->word[1];
unsigned int d = value->word[0];
unsigned int diva = a / 5;
unsigned int divb = b / 5;
unsigned int divc = c / 5;
unsigned int divd = d / 5;
value->word[3] = diva;
value->word[2] = divb;
value->word[1] = divc;
value->word[0] = …Run Code Online (Sandbox Code Playgroud)