发布网友 发布时间:2023-06-29 08:35
共4个回答
热心网友 时间:2024-10-23 21:57
#include<stdio.h>
unsigned int SetBit(unsigned int *num, int pos, int value);
void main()
{
unsigned int a = 0x1234abcd;
printf("a=0x%08x\n",a);
printf("a(0,0)=0x%08x\n",SetBit(&a,0,0));
printf("a(0,1)=0x%08x\n",SetBit(&a,0,1));
printf("a(31,1)=0x%08x\n",SetBit(&a,31,1));
printf("a(31,0)=0x%08x\n",SetBit(&a,31,0));
printf("a(28,0)=0x%08x\n",SetBit(&a,28,0));
printf("a(28,1)=0x%08x\n",SetBit(&a,28,1));
}
/*
将num第pos位设置为value
pos取值范围0-31
value取值范围0,1
*/
unsigned int SetBit(unsigned int *num, int pos, int value)
{
*num &= ~(1<<pos); //将*num的第pos位设置为0
*num |= value<<pos;
return *num;
}
热心网友 时间:2024-10-23 21:58
十六进制替换,可以先 “与” 运算,然后“加”运算 完成。热心网友 时间:2024-10-23 21:58
int func(int *num,int bit,char value)热心网友 时间:2024-10-23 21:59
问题能详细点吗?输入16进制的数,然后替代的数是16进制的?输入16进制?。。。