Fastest way to convert binary to decimal?

前端 未结 6 1662
花落未央
花落未央 2020-12-16 05:21

I\'ve got four unsigned 32-bit integers representing an unsigned 128-bit integer, in little endian order:

typedef struct {
    unsigned int part[4];
} bigint         


        
6条回答
  •  被撕碎了的回忆
    2020-12-16 05:56

    I know this question is old, but I want to contribute as none put a way avoiding the division cycle. This one uses pow2, I haven't tested the benchmark but in theory should be faster than any other, and also could be tweaked in the pow function as well.

    #include 
    #include 
    using namespace std;
    
    #define MathBintodec(arr,len)({int dec=0;int ci_;for(ci_=len;ci_--;)dec+=arr[ci_]*pow(2,len-ci_-1);dec;})
    
    int main(){
        int r[]={1,0,0,1,0,0};
        cout<

    Output: 36

提交回复
热议问题