开发者

toggle a bit at ith positon [duplicate]

开发者 https://www.devze.com 2023-01-15 07:28 出处:网络
This question already has answers here: Closed 12 years ago. 开发者_如何学编程 Possible 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

精彩评论

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