位运算,强制转换!
以下函数是想实现,数X1,X2二进制低random位转换,但是没有实现!
请问这是怎么回事啊?是不是强制转换出的问题?
谢谢!
void genetic_crossover(int l,int X1,int X2)
{
srand( (unsigned)time( NULL ) );
int y1,y2,random;
random=rand()%l;
if (random==0)
{
random=l;
}
y1=X1%(int)pow(2,random);
y2=X2%(int)pow(2,random);
X1=(X1&((int) pow(2,random) ))+y2;
X2=(X2&((int) pow(2,random) ))+y1;
cout < <oct < <random < <endl;
cout < <hex < <y1 < <endl;
cout < <hex < <y2 < <endl;
cout < <hex < <X1 < <endl;
cout < <hex < <X2 < <endl;
}
[解决办法]
帮顶,接分。