G
Gaijinco
For some time now I have forced myself to use size_t instead of int
when I'm using a loop to go thru an array.
But today I found something odd:
long hex2long(const string& s)
{
string alpha="0123456789ABCDEF";
const long base=16;
long power=1, n=1;
for(int i=s.size()-1; i>=0; --i)
{
n+=power*alpha.find(s);
power*=base;
}
return n;
}
This works, but if I make the change the int for size_t, the program
behavies on a very unspected way.
What's wrong with that code? When I should definitely use size_t insted
of int?
Thanks.
when I'm using a loop to go thru an array.
But today I found something odd:
long hex2long(const string& s)
{
string alpha="0123456789ABCDEF";
const long base=16;
long power=1, n=1;
for(int i=s.size()-1; i>=0; --i)
{
n+=power*alpha.find(s);
power*=base;
}
return n;
}
This works, but if I make the change the int for size_t, the program
behavies on a very unspected way.
What's wrong with that code? When I should definitely use size_t insted
of int?
Thanks.