Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 524
nonopolarity Avatar asked Dec 02 '25 11:12

nonopolarity


2 Answers

x & (~(1 << 6))

like image 151
President James K. Polk Avatar answered Dec 07 '25 02:12

President James K. Polk


x&= ~(1 << 5)

like image 34
MSN Avatar answered Dec 07 '25 00:12

MSN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!