简体   繁体   English

将非常大的二进制数字表示形式转换为十进制表示形式的最快方法是什么?

[英]What is the fastest way to convert very large binary number representation to decimal representation?

I've got very big number stored in binary representation and I need to output it in decimal representation: 我用二进制表示形式存储了很大的数字,我需要用十进制表示形式输出它:

struct BigInteger {
    int *parts; // one part stores 12 bits of number, range: 0 to 0xfff
    int parts_n;
};

void convertToDecString( BigInteger *in, std::string &out );

I can't find any approach, that would do it in linear time. 我找不到任何可以在线性时间内完成的方法。

For demostration you can chose any order for parts. 对于演示,您可以选择零件的任何顺序。 I've got it ordered in way, that [0] is lowest value, and [n-1] is the highest value. 我已经按顺序排序,[0]是最低值,[n-1]是最高值。

I am afraid it cannot be done in linear time, because every read bit affects all digits of the decimal representation. 恐怕它不能在线性时间内完成,因为每个读取位都会影响十进制表示形式的所有数字。 The longer the digit, the longer every new read bit takes. 数字越长,每个新的读取位花费的时间越长。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM