gpt4 book ai didi

c - 如何在C中将*x的第n位设置为v值

转载 作者:行者123 更新时间:2023-11-30 20:32:06 24 4
gpt4 key购买 nike

我需要实现这个方法。

我有未签名的* x ,我需要设置v第 n 位的值,使用 C 中的按位运算符。

void set_bit(unsigned * x,
unsigned n,
unsigned v){

//I need the code here, thanks for your help!
}

最佳答案

这里有一个宏可以做到这一点

#define SETBIT(var, bit) ((var) |= (1 << (bit)))

关于c - 如何在C中将*x的第n位设置为v值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48471783/

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