2013-11-21 5 views
0

나는 꽤 못생긴 코드 조각을 가지고있다. 0xff8 ~ 0xfff 중 하나인지 16 진수로 단일 12 비트 데이터를 비교하려고합니다. 코드는 해당 범위의 숫자에 맞는 경우 true를 반환합니다. 어떤 제안? 감사!else else if 코드를 여러 개 최적화하기

/******************************************************************/ 
/* summary: Checks if the cluster is the last cluster in a file. */ 
/* return: returns 1 if true and 0 if false      */ 
/******************************************************************/ 
int lastCluster(unsigned int cluster){ 
    /*Compares the values of the cluster. The cluster is the last cluster in a 
    file if the cluster has a value of 0xff8-0xfff.*/ 
    if(cluster == 0xff8){ 
     return (1); 
    } 
    else if(cluster == 0xff9){ 
     return (1); 
    } 
    else if(cluster == 0xffa){ 
     return (1); 
    } 
    else if(cluster == 0xffb){ 
     return (1); 
    } 
    else if(cluster == 0xffc){ 
     return (1); 
    } 
    else if(cluster == 0xffd){ 
     return (1); 
    } 
    else if(cluster == 0xffe){ 
     return (1); 
    } 
    else if(cluster == 0xfff){ 
     return (1); 
    } 
    else{ 
     return (0); 
    } 
} 

답변

4

당신은

if (cluster>=0xff8 && cluster<=0xfff) 
    return 1; 
return 0; 
+0

와우, 대단히 감사합니다 단일 테스트로이 결합 할 수 있습니다! – user2989964

관련 문제