quietsamurai98 - 3 years ago 166

C++ Question

I am trying to roll my own arbitrary size unsigned integer class, but I am having trouble finding a way to convert the

`std::vector<bool>`

`unsigned long long sum = 0LL;`

for(unsigned long long i=0; i<64LL && i<bit_list.size(); i++){

if(bit_list[i]){

sum |= 1LL << i;

}

}

return std::to_string(sum);

However, this only works for numbers below 2^64, because of the limitations of

`std::to_string`

`unsigned long long`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

Pseudo code:

```
string s;
your_bitlist_class i;
if ( i > 0 )
{
while ( i > 0 )
{
s.insert( 0, std::to_string( i % 10 ) );
i /= 10;
}
}
else
{
s = "0";
}
```

Optimization is left as an exercise for the reader.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**