'programming'에 해당되는 글 387건

  1. 2011.08.18 16진수값을 10진수의 숫자값으로 바꾸기

반응형


입력 : 16진수값(0~9, A~F)를  10진수의 값으로 바꾸기

int hextodec( char *str )
{
    int nInt = 0;
    int nSeed = 0;

    char cChar;
   
    int i;

    for( i = 0; str[ i ]; i++ )
    {
        nInt = nInt << 4;

        switch( str[ i ] )
        {
            case 'F':
            case 'f':
                nSeed = 15;
                break;
            case 'E':
            case 'e':
                nSeed = 14;
                break;
            case 'D':
            case 'd':
                nSeed = 13;
                break;
            case 'C':
            case 'c':
                nSeed = 12;
                break;
            case 'B':
            case 'b':
                nSeed = 11;
                break;
            case 'A':
            case 'a':
                nSeed = 10;
                break;
            default:
                cChar = str[ i ];
                nSeed = atoi( &cChar );
                break;
        }
        nInt += nSeed;
    }

    return nInt;
}

반응형
Posted by 공간사랑
,