gpt4 book ai didi

c - 如何解释函数中的十六进制值的说明

转载 作者:行者123 更新时间:2023-11-30 18:08:19 25 4
gpt4 key购买 nike

我的程序运行得很好,但这是通过反复试验才实现的;我试图从首要原则出发,了解事物的真正运作方式。我将不胜感激任何解释。这个与十六进制值通信的函数是什么?

  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;
}
}

最佳答案

Logical &正在执行操作。

0x3C is equal to  0011 1100 . 
0xf0 is equal to 1111 0000
0xf is equal to 0000 1111

取决于所操作的数据类型。一个字节由 8 位组成,如果所有位均已设置,则其等效的十六进制值为 0xFF。

关于c - 如何解释函数中的十六进制值的说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3521058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com