在ith位置切换一点 [英] toggle a bit at ith positon

查看:77
本文介绍了在ith位置切换一点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何设置,清除和切换是C中的一小部分?

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

有人可以帮助我如何在ith位置切换一点. 一种方法是执行((n>>i) ^ 1) << i.还有其他方法吗?

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很简单,不是吗?

这篇关于在ith位置切换一点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆