我的计划运作完美,但这是通过反复试验实现的;我试图抓住事情真正起作用的原则。我将不胜感激任何解释。这个函数与十六进制值通信的是什么?
for (i=0; i<5;i++)
{
cd=(int)(((numpairs[i])&0xf0)>>4);
if((numpairs[i]&0xf)>(0x0))
{
if(highest<cd)
{
//printf("%d\n",cd);
highest= cd;
cd=-1;
winner = i+1;
// printf(" highest: %d winner: %d\n", highest,winner);
}
if(highest==cd)
{
highest =0;
break;
//printf(" highest: %d winner: %d", highest,winner);
}
}
}
printf("\n---------------RESULT--------------\n");
if(highest>0)
{
printf("Winner is hand %d with a pair of %s\n", winner, values[highest]);
}
else
printf("*** DRAW ***\n");
// ========================Function 2=======================================
pairs findpairs(card *hand)
{
int i;
card cd1, cd2,cd3, card=0;
pairs numpairs=0;
for(i=1; i<4;i=i+2)
{
cd1=hand[i];
cd2=hand[i-1];
cd3=hand[i+1];
cd1= (cd1&0x3c)>>2;
cd2= (cd2&0x3c)>>2;
cd3= (cd3&0x3c)>>2;
if (cd1==cd2 || cd1==cd3)
{
numpairs++;
// printf("num pairs: %d\n", numpairs);
card=cd1;
}
}
答案 0 :(得分:0)
Logical &操作。
0x3C is equal to 0011 1100 .
0xf0 is equal to 1111 0000
0xf is equal to 0000 1111
取决于操作它的数据类型。一个字节由8位组成,如果所有位都置位,则其十六进制等效值为0xFF。