开发者

toggle a bit at ith positon [duplicate]

This question already has answers here: Closed 12 years ago. 开发者_如何学编程

Possible Duplicate:

How do you set, clear and toggle a single bit in C?

Can some one help me how to toggle a bit at ith position. One way is to do ((n>>i) ^ 1) << i. Are there any other ways ?


n ^= 1U << i is easy enough, isn't it?


You could do

pow(2, i) ^ n
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜