开发者

What are the best methods to "Clear the 6th bit" of an integer?

开发者 https://www.devze.com 2022-12-25 00:34 出处:网络
What are the best methods to \"Clear the 6th bit\" of an integer? And, is your solution platform independent?(32 or 64 bit integer, etc).If not开发者_开发技巧, can you give a solution that is platfor

What are the best methods to "Clear the 6th bit" of an integer?

And, is your solution platform independent? (32 or 64 bit integer, etc). If not开发者_开发技巧, can you give a solution that is platform independent?

Update: we don't know whether that bit is set or unset when it was given... also, any language is ok... i know of a solution that is platform independent that requires 2 operators... maybe there are various methods or simpler solutions.

Update: more clearly: clear the 6th least significant bit of an interger.


x & (~(1 << 6))


x&= ~(1 << 5)


Perhaps this in c?

value&~(1<<6)


If you're sure it's already set, just subtract 64.

Update: adding the test

if((x % 128) / 64 > 0)
  x -= 64;

As far as I can see right now, this doesn't make any assumptions about the platform or language support.

0

精彩评论

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