大概写了一下,就算示意吧,那个表的数据我就不算了,太麻烦了- #include <stdio.h>
-
- typedef unsigned int UINT32;
-
- typedef struct data {
- UINT32 retvalue;
- UINT32 halfdata;
- int type; //0 : directly return ; 1: need to go on
- } ITEM_DATA;
-
- ITEM_DATA hash [256] = {
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},
- {1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0}
- };
-
-
- UINT32 GreaterEqualBit2(UINT32 n)
- {
- int t1=0,t2=0;
- unsigned char *v= (unsigned char *)&n;
- //find first 2 v that large than zero
- if (v[3]>0) {
- if( hash[v[3]].type == 0 ) {
- //3
- return ( hash[v[3]].retvalue )<<24;
- } else {
- if (v[2]>0) {
- //3,2
- return ((hash[v[3]].halfdata)<<24)+((hash[v[2]].halfdata)<<16);
- }
- else {
- if(v[1]>0) {
- //3,1
- return ((hash[v[3]].halfdata)<<24)+((hash[v[1]].halfdata)<<8);
- }
- }
- //3,0
- return ((hash[v[3]].halfdata)<<24)+((hash[v[0]].halfdata));
- }
- }
- else {
- if(v[2]>0) {
- if( hash[v[2]].type == 0 ) {
- //2
- return ( hash[v[2]].retvalue )<<16;
- } else {
- if (v[1]>0)
- //2,1
- return ((hash[v[2]].halfdata)<<16)+((hash[v[1]].halfdata)<<8);
- else
- //2,0
- return ((hash[v[2]].halfdata)<<16)+((hash[v[1]].halfdata) );
- }
- }
- else
- if(v[1]>0) {
- if( hash[v[1]].type == 0 )
- //1
- return ( hash[v[1]].retvalue )<<8;
- else
- //1,0
- return ((hash[v[1]].halfdata)<<8)+((hash[v[1]].halfdata) );
- }
- }
- //0
- return hash[v[0]].retvalue ;
- }
-
- int main(int argc, char * argv[]){
- int i;
- for (i=0x11 ; i<0x111121 ; i++)
- printf(" input %d , output %X \n",i,GreaterEqualBit2(i));
-
- return 0;
- }
复制代码 |