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.
精彩评论