toggle a bit at ith positon [duplicate]

一个人想着一个人 提交于 2019-12-08 18:24:51

问题


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 ?


回答1:


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




回答2:


You could do

pow(2, i) ^ n


来源:https://stackoverflow.com/questions/3681684/toggle-a-bit-at-ith-positon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!