c++11 - String To Int For BigInt Manual Conversion -


i have problem converting string int, need save 5 digit number in each std::list element. use this:

for(int =0; i< e.length(); ++i) {     tmp = tmp*10+ e[i] - '0';     ++rads;     if(rads>4)      {        numbs.push_back(tmp);        rads=0;        tmp=0;     } } 

if in input number is:

10000 00012 02345 00001

in list get:

10000 12 2345 1

all problem save without loosing zeros after

rads>4 or rads==rads

what tried:

to save base #define-d rads

for(int =0; i< e.length(); ++i) {     tmp = tmp*10+ e[i] - '0';     if(tmp>=rads) // rads defined 10000     {        cumul = cumul*10+tmp/rads;        tmp = tmp%rads;     }    if(cumul>=rads) // rads defined 10000     {        numbs.push_back(cumul);        cumul = 0;     }  } 

i've read , looked various sources codes , articles related this, in none of them there suitable solution (not code, idea @ least) or solution save int/char [by 1 digit]. 1 easiest way, expensive process 1 int 2^4 bits occupied. that's why looking way save 5 digit integer in x32 word, possible fit working time limits , avoid rewriting of realized code "+ - / * %" in search more or less close question posted close mine how split big numbers?

"leading zeroes" property of how render numbers human viewing (i.e. string contains digit characters). not inherent value itself.

consequently, leading zeroes don't exist.

you can add leading zeroes eventual output if wish.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -