home · blog · groups · about us · contact us
DevelopmentNow Blog
 Thursday, July 13, 2006
 
 

Up to base 36, anyhow. This is a port from old C. I think it works (did it on paper).

// return decimal version of any number up to base 36
// e.g. strtonum("110", 16) returns 272 (which is 110 in base 16)
int strtonum(orig, base)
{
    string digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int retval = 0;

    for (int i = 0; i < orig.length; i++)
    {
        string character = orig[i];

        for (j = 0; j < digits.length; j++)
        {
            if (character == digits[j])
            {
                retval = retval * base + j;
                break;
            }
        }
    }

    return retval;
}

July 13, 2006    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]

Related posts:
SubSonic DAL layers in Visual Studio
Intro to BDD
Easy FTP Uploads in your EXEs
FireBug 1.0.1 is out
WYSIWYG editor in minutes
jQuery for javascript effects


« Portland Code Camp 2.0 | Main | Free and Cheap Replacements for Notepad »