- 论坛徽章:
- 0
|
原帖由 思一克 于 2008-8-28 10:25 发表 ![]()
原来如此.
能给出你的实验程序吗(和移位比较)?
#define TIME 1<<26
char table[8]={1,2,4,8,16,32,64,128};
void withshift()
{
int p;
char t;
for(p=0;p<TIME;p++)
{
t=table[rand()&7];
int i=0;
char n=1;
int out=0;
do
{
if((n<<i++)==t)
{
out=i;
break;
}
}while(i<=8);
}
}
void withswitch()
{
int p;
char t;
for(p=0;p<TIME;p++)
{
t=table[rand()&7];
int out=0;
switch(t)
{
case 1:out=1;break;
case 2:out=2;break;
case 4:out=3;break;
case 8:out=4;break;
case 16:out=5;break;
case 32:out=6;break;
case 64:out=7;break;
default:out=8;break;
}
}
}
int main()
{
withshift();
//withswitch();
return 0;
}
|
|
|